# Armstrong Number In C

Armstrong Number In C

## What Is Armstrong Number In C

A number is thought of as an Armstrong number if the quantity of its own digits raised to the facility number of digits gives the number itself. For example, 0, 1, 153, 370, 371, 407 are three-digit Armstrong numbers and, 1634, 8208, 9474 are four-digit Armstrong numbers and there are many more.

Lets judge 407 by now it is a three-digit number consequently it could be expressed as:

Armstrong Number in C
Since 407 can be expressed as a quantity of the cube of its digits, fittingly it is an Armstrong number.

We will now mood an Algorithm to check for the number whether its an Armstrong number or not. So following are the steps that we would dependence to follow to test for the Armstrong number. The idea is to right of entry one digit at a era from the lead of the number, if the number is 4 0 7, along with we will be responsive concerning speaking 7 later 0, and later 4.

## Check armstrong number in C

When You Taking a Number, From That the sum of the Part Digit cube of  a number is equal to this number. Mean Suppose You Will Take 153 That means 1 cube + 5 cube + 3cube equal to 153 it ia Armstrong Number.

## Armstrong number logic in C

Suppose You Will Take 153 That means 1 cube + 5 cube + 3cube equal to 153 it ia Armstrong Number. So Below Code Here You Understand All Step By Step.

## Armstrong number code in C :

Explain Video Here

## Algorithm (for a 3-digit Number)

Step 1: Start.

Step 2: Read an integer input number.

Step 3: Declare andInitialise the variables current_digit , sum = 0 and num = number.

Step 4: Repeat Steps 5 to 7 Until num > 0.

Step 5: current_digit = (num % 10). %10 compensation the last digit of the current number.

Step 6: total = quantity + (current_digit * current_digit * current_digit). The regulating current_digit is multiplied three times because we are checking for a three digit Armstrong number.

Step 7: num = num / 10

After management the last digit we compulsion to cut off it. /10 will pay for an integer such that the order of the number will be edited and the adjacent digit will become the last digit.

Step 8: Check if sum == number. Then Print It is an Armstrong Number. Else Print It is not an Armstrong Number.

Step 9: END

### Code :-

#include<stdio.h>
#include<math.h>

int isArmstrong(int number) {
int current_digit, sum = 0, num = number, number_of_digits;

while (num > 0) {
current_digit = num % 10;
// Calculating the power of the remainder using pow() and storing in sum.
sum = sum + pow(current_digit, 3);
num = num / 10;
}

// Return 1 if the number is Armstrong else return 0.
if (sum == number) {
return 1;
} else {
return 0;
}
}

int main() {
int number = 371, isArmstrongNumber;

if (sum == number){
printf(“%d is an Armstrong Number.”, number);
} else {
printf(“%d is not an Armstrong Number.”, number);
}

// Calling the isArmstrong function.
isArmstrongNumber = isArmstrong(number);

if (isArmstrongNumber == 1) {
printf(“%d is an Armstrong Number.”, number);
} else {
printf(“%d is not an Armstrong Number.”, number);
}

return 0;
}

## Algorithm (for N-digit Number)

Step 1: Start

Step 2: Read an integer input number.

Step 3: Declare andInitialise the variables current_digit, quantity = 0, digits = 0 and num = number.

Step 4: Calculate the number of digits in the input integer number and buildup it in the modifiable number_of_digits.

Step 5: Repeat Steps 5 to 7 Until num > 0

Step 6: current_digit = (num % 10)

Step 7: quantity = sum + mnumber_of_digits

Step 8: num = num / 10

Step 9: Check if sum == number Then

Print It is an Armstrong Number.

Else

Print It is not an Armstrong Number.

Step 10: END

## Armstrong Number in C Program

### Code: –

#include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf(“enter the number=”);
scanf(“%d”,&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf(“armstrong number “);
else
printf(“not armstrong number”);
return 0;
}

### Output:-

Enter any Number : 153

153 is an Valid Armstrong Number.

## What is Armstrong number in C using while loop?

write the c program to check the number is Armstrong or not. you can  understand what is Armstrong number. Armstrong number is a number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers.

## Logic for armstrong number in C

Suppose You Will Take 153 That means 1 cube + 5 cube + 3cube equal to 153 it ia Armstrong Number.

## Armstrong Number in C Using Function

Now In this C program, we will use interchange functions for checking for the Armstrong number. The output of this will be the joined as the program that we have discussed above, but the structure of the program is changed. It is generally a enjoyable practice to use functions even though making a program. This makes the code readable and helps in easy debugging.

## How to find armstrong number in c

Check Below How to FInd This.

### Code :-

#include<stdio.h>
#include<math.h>

int countNumberOfDigits(int number) {
// Calculating the number of digits.
while (number > 0) {
// This will decrease the order of the number in each iteration.
number = number / 10;
number_of_digits++;
}

return number_of_digits;
}
int isArmstrong (int number){
int current_digit, sum = 0, num = number, number_of_digits;
number_of_digits = countNumberOfDigits(num)
while(num > 0) {
current_digit = num % 10;
// Calculating the power of the remainder using pow() and storing in sum.
sum = sum + pow(current_digit, number_of_digits);
num = num / 10;
}
// return 1 if the number is Armstrong else return 0.
if(sum == number)
return 1;
else
return 0;
}

int main() {
int number, isArmstrongNumber;
scanf(“%d”, &number);
isArmstrongNumber = isArmstrong(number);
if(isArmstrongNumber == 1)
printf(“%d is an Armstrong Number.”, number);
else
printf(“%d is not an Armstrong Number.”, number);

return 0;
}

### OutPut :-

Enter any Number: 54748
54748 is an Armstrong Number which is Valid.

## Armstrong number in c using for loop

When the utter of the cube of the individual digits of a number is equal to that number, the number is called Armstrong number. It is Used By Loop Such Like For Loop, While Loop and Do While Loop.

### Code:-

#include <stdio.h>

void main(){
int num,r,sum=0,temp;

printf(“Input a number: “);
scanf(“%d”,&num);

for(temp=num;num!=0;num=num/10){
r=num % 10;
sum=sum+(r*r*r);
}
if(sum==temp)
printf(“%d is an Armstrong number.\n”,temp);
else
printf(“%d is not an Armstrong number.\n”,temp);

}

### OutPut:-

Enter any Number : 153

153 is an Valid Armstrong Number.