Pages

Ads 468x60px

Saturday, 2 June 2012

C PROGRAM FOR AMSTRONG NUMBER


C PROGRAM FOR AMSTRONG NUMBER



     armstrong number c program: c programming code to check whether a number is armstrong or not. A number is armstrong if the sum of cubes 
of individual digits of a number is equal to the number itself. For example 371 is an armstrong number as 33 + 73 + 13 = 371. Some other armstrong numbers are: 0, 1, 153, 370, 407.







CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,t,s=0,k;
clrscr();
printf("Enter the n value:");
scanf("%d",&k);
n=k;
while(n>0)
{
t=n%10;
s=s+t*t*t;
n=n/10;
}
if(k==s)
{
printf("given %d is armstrong number",k);
}
else
{
printf("not armstrong number");
}
getch();
}

0 comments:

Post a Comment

Total Pageviews