In this, we are going to see a program in which it will check whether the number is an Armstrong number or not using Function in C programing Language.
//WAP to check the Armstrong number using function
#include <stdio.h>
int Armstrong(int n)
{
int d, sum = 0;
int temp;
temp = n;
while (n > 0)
{
d = n % 10;
sum = sum + (d * d * d);
n = n / 10;
}
if (temp == sum)
{
printf("The number %d is Armstrong number", temp);
}
else
{
printf("The number %d is not an Armstrong number", temp);
}
return 0;
}
void main()
{
int num;
printf("Enter the number to check armstrong number: ");
scanf("%d", &num);
Armstrong(num);
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP