Problem:
A 3-digit number such that square of sum of the first,second and twice the third digit is equal to the same number. 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=2*b+d+e; //i.e.,, x+y+2*z if xyz is a 3-digit number
//caluclate cube of middle digit
g=f+f; //square of that resultant
if(a==g)//same number is eqaul to the resultant checking
{
printf("The answer for the problem is=%d",a);
}
}
}
A 3-digit number such that square of sum of the first,second and twice the third digit is equal to the same number. 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=2*b+d+e; //i.e.,, x+y+2*z if xyz is a 3-digit number
//caluclate cube of middle digit
g=f+f; //square of that resultant
if(a==g)//same number is eqaul to the resultant checking
{
printf("The answer for the problem is=%d",a);
}
}
}
No comments:
Post a Comment