Armstrong Number in C Using Function

Armstrong Number in C Using Function. In this program, we can find whether the number is an Armstrong number or not using a function in the c program for beginners.

Armstrong Number Definition

The sum of the cubes of its own digits is equal to an Armstrong number, also known as a narcissistic number. 

As a result, narcissistic numbers are numbers that can be represented by manipulating their digits mathematically. 

A whole number, or integer, is the sum of its digits’ nth powers. 

Function Definition in C

A function is a collection of statements that work together to complete a task. 

Every C program contains at least one function, main(), and even the simplest programs can specify more functions. 

The name, return type, and parameters of a function are all specified in a function declaration. 

Armstrong Number in C Using Function

#include<stdio.h>
int func(int number)
{
int num = 0;
int power = 0;
int sum = 0;
int n = number;
while(n!=0)
{
num = n % 10;
power = num*num*num;
sum += power;
n /= 10;
}
if(sum == number) return 0;
else return 1;
}
int main()
{
int number;
printf("Enter The Number");
scanf("%d",&number);
if(func(number) == 0)
printf("%d is Armstrong Number\n", number);
else
printf("%d is Not Armstrong Number", number);
return 0;
}

Output: 

Enter The Number45 

45 is Not Armstrong Number