Program:
/* C Program to find given number is amstrong or not for N digit number*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
int temp = 0,n,i = 0,r = 0,m;
long int sum = 0;
printf("Enter N Value:");
scanf("%d",&n);
temp = n;
m = n;
while( temp > 0)
{
i++;
temp = temp/10;
}
while( n > 0 )
{
r = n%10;
sum = sum + pow(r,i);
n = n/10;
}
if(sum == m)
{
printf("Given Number is AMSTONG");
}
else
{
printf("Given Number is not AMSTRONG");
}
}
Output:
/* C Program to find given number is amstrong or not for N digit number*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
int temp = 0,n,i = 0,r = 0,m;
long int sum = 0;
printf("Enter N Value:");
scanf("%d",&n);
temp = n;
m = n;
while( temp > 0)
{
i++;
temp = temp/10;
}
while( n > 0 )
{
r = n%10;
sum = sum + pow(r,i);
n = n/10;
}
if(sum == m)
{
printf("Given Number is AMSTONG");
}
else
{
printf("Given Number is not AMSTRONG");
}
}
Output: