Program to check whether a given number is Armstrong or not - 100 Most Important C# Programs

100 Most Important C# Programs

65. Program to check whether a given number is Armstrong or not.

Code:

# include <stdio.h>

# include <conio.h>

main( )

{

int i,n,s,r,k;

clrscr( );

printf(“enter a number”);

scanf(“%d”,&n);

k=n;

s=0;

while(n>0)

{r

=n%10;

s=s+(r*r*r);

n=n/10;

}

if(k==s)

printf(“given number is Armstrong

%d”,k);

else

printf(“given number is not Armstrong

%d”,k);

}

getch();

}