Tuesday, August 31, 2010
C Program to find four digit perfect square in which the number represented by the first two digits and last two digits are also perfect square | code | output
#include<stdio.h>
#include<math.h>
int main()
{
int i,left,right,a,d1,d2,d3,d4,x,y,num;
printf("Following numbers are the desired numbers:\n");
for(i=1000;i<=9999;i++)
{
//Find square root of i
a=sqrt(i);
//Test whether i is perfect square or not
if(i==a*a)
{
//Find all four digits
num=i;
d4=num%10;
num=num/10;
d3=num%10;
num=num/10;
d2=num%10;
num=num/10;
d1=num%10;
num=num/10;
//store first two digits
left=d1*10+d2;
//store last two digits
right=d3*10+d4;
//Check if these are perfect numbers or not
x=sqrt(left);
y=sqrt(right);
//print the number if all the conditions are satisfied
if(left==x*x&&right==y*y)
printf("%d \n",i);
}
}
}
Finding square of a number
Subscribe to:
Post Comments (Atom)
Very good post Look Here best mathematics exam preparation with good teacher with online ....Online Maths Tutors
ReplyDelete