Monday 30 September 2013

c program to check whether given number is armstrong or not

"a number is said to be an armstrong number if sum of cubes of each digit of  a
number is equal to the given number."


#include<stdio.h>
#include<conio.h>
void main()
{
int n,c,sum=0,t;
clrscr();
printf("enter a digit");
scanf("%d",&n);
t=n;
while(n!=0)
{
c=n%10;
sum=sum+(c*c*c);
n=n/10;
}
if(sum==t)
printf("the given number is a armstrong number..");
else
printf("the number is not an armstrong number..");
getch();
}

No comments:

Post a Comment