• 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.

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. void main(){
  4. int number, originalNumber, rem, result = 0;
  5.  
  6.     printf("Enter a three digit number to check armstrong number or not: ");
  7.     scanf("%d", &number);
  8.  
  9.     originalNumber = number;
  10.  
  11.     while (originalNumber != 0)
  12.     {
  13.         rem = originalNumber%10;
  14.         result += rem*rem*rem;
  15.         originalNumber /= 10;
  16.     }
  17.  
  18.     if(result == number)
  19.         printf("%d is an Armstrong number.",number);
  20.     else
  21.         printf("%d is not an Armstrong number.",number);
  22.  
  23.     getch();
  24.     
  25. }

 Output:


Armstrong number in c program

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu