C Program to check armstrong numbers

Simple C program to check Armstrong numbers: A number is called Armstrong number if the sum digits raise to power total number of digits is equal to the number itself. For example 153=1^3+3^3+5^3 so 153 is an Armstrong number and number 30 is not an Armstrong number because 3^2+0^2 !=30.
#include<stdio.h>
#include<stdio.h>
#include<math.h>
int main()
{
 int n,num=0,temp,temp1,digits=0;
 printf("Enter a number: ");
 scanf("%d",&n);
 temp=n;
 temp1=n;
 while(temp!=0)
 {
 
  digits++;
  temp=temp/10;
 }
 while(temp1!=0)
 {
  int rem=temp1%10;
  num=num+pow(rem,digits);
  temp1=temp1/10;
 }
 if(num==n)
 {
  printf("%d is armstrong number\n",n);
 }
 else
 {
  printf("%d is not armstrong\n",n);
 }
 return 0;
}





Popular posts from this blog