I am using Code :: Block 10.02 and When print Amstrong Number in CI I expect this result:
153
370
371
407
But he only prints:
153
370
371
This is my code in C:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
int a,b,c;
for (a=1;a<=9;a++)
for(b=0;b<=9;b++)
for(c=0;c<=9;c++)
{
if(pow(a,3)+pow(b,3)+pow(c,3)==100*a+10*b+c)
printf("\n%d%d%d",a,b,c);
}
}
And this is my screen: http://daynhauhoc.com/uploads/default/3011/9598a2ad2183198f.png
But, when I use this code, it works very well:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
int a,b,c;
for (a=1;a<=9;a++)
for(b=0;b<=9;b++)
for(c=0;c<=9;c++)
{
int d=pow(a,3)+pow(b,3)+pow(c,3);
int e=100*a+10*b+c;
if(d==e)
printf("\n%d%d%d",a,b,c);
}
}
Will someone please tell me an explanation?
source
share