Write a program to check the entered number is armstrong or not.

Write a program to check the entered number is armstrong or not.

 

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int rem,res=0,n1,n; 

printf("enter a number:\n");

scanf("%d",&n);

n1=n;

while(n!=0)

{

rem=n%10;

res=res+(rem*rem*rem);

n=n/10;

}

if(res==n1)

{

printf("%d is armstrong number",n1);

}

else

{

printf("%d is not armstrong number",n1);

}

getch();

}

===============================================

 

Output:

 

Enter a number:153

153 is armstrong number

 


Comments