Sunday, September 12, 2010

C Program to Check whether a number is an Armstrong Number or not

#include<stdio.h> 
#include<conio.h> 
#include<math.h> 
void main() 

int n,sum=0,rem=0,cube=0,n1;
clrscr();
printf("\n\tEnter a number :" );
scanf("%d",&n);
n1=n;
while(n!=0)
{
rem=n%10;
cube=pow(rem,3);
sum=sum+cube;
n=n/10;
}
if(sum==n1)
printf("\n\tIt is an Armstrong's Number ");
else
printf("\n\tIt is not an Armstrong's Number ");
getch(); 

No comments:

Post a Comment