C program to check that given number is armstrong number or not.

#include<stdio.h>
#include<conio.h>
#include<math.h>
main(){
int n,i,sum=0,q,r;
clrscr();
printf("Enter an integer number\n");
scanf("%d",&n);
if (n>0){
q=n;
while (q!=0){
r=q%10;
q=q/10;
sum=sum+pow(r,3);
}
if (n==sum) printf("%d is a armstrong number.\n",n);
else printf("%d is not a armstrong number.\n",n);
}
else printf("Wrong input");
getch();
return 1;
}

No comments:

Post a Comment