One of the questions given to us for the lab exam was to generate the first 10 armstrong numbers. I could generate upto 5 numbers correctly..the rest are wrong.
#include<stdio.h>
#include<conio.h>
void main()
{
int n=1,a,b,i=1,r;
clrscr();
while(i<=10)
{
a=0;
b=n;
do
{
r=b%10;
a=a+r*r*r;
b=b/10;
}while(b>0);
if(a==n)
{
printf("\t%d",n);
i++;
n++;
}
else
n++;
}
getch();
}
the output i got is :
1 153 370 371 407 -729 -216 -125 -64 -1
What should I do to get the correct output?