GoogelAddUnit1

Monday, 16 April 2012

WRITE A C-PROGRAM TO TEST THE GIVEN NUMBER IS ARMSTRONG NUMBER (OR) NOT.

AIM:a pragram to test the given number is an armstrong number(or) not.

PROGRAM:
#include<stdio.h>
main()
{
int i=1,n,sum=0,c,k;
printf("enter the value of n");
scanf("%d",&n);
k=n;
while(n>0)
{
d=n%10;
c=d*d*d;
sum=sum+c;
n=n/10;
}
if(sum==k)
printf("it is an armstrong number");
else
printf("it is not an armstrong number");
}

OUTPUT:
enter the value of n
153
it is an armstrong number
enter the value of n
23
it is not an armstrong number

No comments:

Post a Comment