Saturday, October 8, 2011

C program to check for Armstrong Number


Write a program in C to check whether the given number is Armstrong or not....



Program...

#include<stdio.h>
#include<conio.h>
void main()
{
int num,r,sum=0,temp;
clrscr();
printf("\nEnter a number:");
scanf("%d",&num);
temp=num;
while(num)
{
r=num%10;
num=num/10;
sum=sum+(r*r*r);
}
if(temp==sum)
printf("\n%d is an armstrong number",temp);
else
printf("\n%d is not an armstrong number",temp);
getch();
}


Output...

0 comments:

Post a Comment

About Me