- Armstrong number is a number which order of n if
- xyz=x n + y n + z n;
- To check three digit Armstrong number in c programming
- 153=13 * 53*33
- In the same way we can also check four digit Armstrong number
- 1634=14+64+34+44 is Armstrong number.
- In c Programming to check a number is armstrong or not we need to split that number and need to find nth power of each number and sum all the results.
- If total sum is equal to the same number then we can say it is Armstrong number.
- Let us see an Example program in c to check a number is Armstrong number or not without using recursion.
- First we will check a three digit number is armstrong number or not
Program #1 : write a c program to check a three digit number is armstrong number or not without using recursion.
- #include <stdio.h>
- #include <stdlib.h>
- void main(){
- int number, originalNumber, rem, result = 0;
- printf("Enter a three digit number to check armstrong number or not: ");
- scanf("%d", &number);
- originalNumber = number;
- while (originalNumber != 0)
- {
- rem = originalNumber%10;
- result += rem*rem*rem;
- originalNumber /= 10;
- }
- if(result == number)
- printf("%d is an Armstrong number.",number);
- else
- printf("%d is not an Armstrong number.",number);
- getch();
- }
Output:
No comments