Saturday, July 6, 2013

Armstrong Number.

I was just writing a program for armstrong number till a given range.
Something wrong with this code ?

#include<stdio.h>
#include<conio.h>

void main()
{

int num,range,temp;
int rem,sum=0;

printf("Enter upper range: ");
scanf("%d", &range);

// Checking is a number is armstrong of not.

printf("Armstrong are:");
for(num=10; num<=range; num++)
{
temp=num;
while(temp>0)
{
rem=temp%10;
sum=sum+(rem*rem*rem);
temp=temp/10;
}
if(num==sum)
{
printf("%d\t",num);
}

}

getch();

}


It is giving following output.

Enter upper range: 2000
Armstrong are:12

Thanx. - Full Post

No comments:

Post a Comment