Thursday 3 October 2013

Determining whether a number is Armstrong number or not using C

#include<stdio.h>
#include<math.h>
main()
{
int num,rem,sum=0,temp;
printf("\n(There is) none worthy of worship except Allah(Subhanahu wa ta'ala).Muhammad(Sallallahu alayhi wasallam) is Messenger of ALLAH(Subhanahu wa ta'ala).\n");
printf("Enter the number:\t");
scanf("%d",&num);
temp=num;
while(num>0)
{
rem=num%10;
sum=sum+pow(rem,3);
num=num/10;
}
if(temp==sum)
printf("Given number(%d) is an Armstrong Number \n",temp);
else
printf("Given number(%d) is not an Armstrong Number \n",temp);
}

No comments:

Post a Comment