Problem:
A 3-digit number such that sum of the individual digits is equal to sum of squares of first and second digits.find that number?
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,g;
clrscr();
//let us consider a for loop from 100 to 1000 because its a 3-digit number
for(a=100;a<1000;a++)
{
b=a%10;//last digit will comes i.e.,, if xyz is 3-digit number then z will comes
c=a/10;;//first 2 digits will comes i.e.,, if xyz is 3-digit number then xy will comes
d=c%10;//by doing this we get middle digit ie,, y
e=a/100;//we get first digit i.e,, x
//caluclate sum
f=b+d+e;
//caluclate cube of middle digit
g=(e*e)+(d*d);//sum of squares of 1st and second digits i.e.,, (x*x)+(y*y)
if(f==g)
{
printf("The answer for the problem is=%d",a);
}
}
}
A 3-digit number such that sum of the individual digits is equal to sum of squares of first and second digits.find that number?
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,g;
clrscr();
//let us consider a for loop from 100 to 1000 because its a 3-digit number
for(a=100;a<1000;a++)
{
b=a%10;//last digit will comes i.e.,, if xyz is 3-digit number then z will comes
c=a/10;;//first 2 digits will comes i.e.,, if xyz is 3-digit number then xy will comes
d=c%10;//by doing this we get middle digit ie,, y
e=a/100;//we get first digit i.e,, x
//caluclate sum
f=b+d+e;
//caluclate cube of middle digit
g=(e*e)+(d*d);//sum of squares of 1st and second digits i.e.,, (x*x)+(y*y)
if(f==g)
{
printf("The answer for the problem is=%d",a);
}
}
}
No comments:
Post a Comment