Write a program to find whether the given number is an Armstrong number
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0,num,digit;
clrscr();
printf("Enter the number: ");
scanf("%d",&n);
num=n;
do
{
digit=n%10;
sum=sum+digit*digit*digit;
n=n/10;
}while(n!=0);
if(sum==num)
printf("It is an Armstrong number");
else
printf("It is not an Armstrong number");
getch();
}
Output:
run 1:
Enter the number: 153
It is an Armstrong number
run 2:
Enter the number: 220
It is not an Armstrong number
No comments: