Easy Programming All

Easy Programming All

Monday, December 17, 2018

WAP in C to check Whether a given Number is Armstrong or Not

#include<stdio.h>
#include<math.h>
int main()
{
int i, n, sum = 0, rem, copy, count = 0;
printf("Enter any integer number to check armstrong or not\n");
scanf("%d",&n);
copy =  n;
while(n > 0)
{
count  =  count + 1;
n = n / 10;
}
n = copy;
while(n > 0)
{
rem = n % 10;
sum = sum + pow(rem, count);
n = n/10;
}
if(copy = = sum)
{
printf("The given %d number is Armstrong",copy);
}
else
{
printf("The given %d number is Not Armstrong",copy);
}
return 0;
}


INPUT 1:
Enter any integer number to check armstrong or not
153
OUTPUT 1:
The given 153 number is Armstrong 
 
INPUT 2:
Enter any integer number to check armstrong or not
1634
OUTPUT 2:
The given 1634 number is Armstrong 
 
INPUT 3:
Enter any integer number to check armstrong or not
126
OUTPUT 3:
The given 126 number is Not Armstrong 


No comments:

Post a Comment