Write a C program to check whether a given number is an Armstrong or not.
Program:
#include<stdio.h>
main()
{
int n,temp,rem,sum=0;
printf("enter a number:-");
scanf("%d",&n);
temp=n;
while(n!=0)
{
rem=n%10;
sum=sum+(rem*rem*rem);
n=n/10;
}
if(temp==sum)
{
printf("given number is armstrong\n");
}
else
{
printf("given number is not armstrong\n");
}
}
output:-
No comments:
Post a Comment