sahajjain01

13.Input a number and check if it's Armstrong.

Aug 16th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. //Program to input a number and check if it's Armstrong.
  2. #include<stdio.h>
  3. #include<conio.h>
  4.  
  5. void main()
  6. {
  7.     int number, sum = 0, temp;
  8.  
  9.     clrscr();
  10.  
  11.     printf("Enter number: ");
  12.     scanf("%d", &number);
  13.  
  14.     temp = number;
  15.  
  16.     while(number != 0) {
  17.         sum = sum + ((number % 10) * (number % 10) * (number % 10));
  18.         number = number / 10;
  19.     }
  20.  
  21.     if(sum == temp)
  22.         printf("The number %d is an Armstrong number.", temp);
  23.     else
  24.         printf("The number %d is not an Armstrong number.", temp);
  25.  
  26.     getch();
  27. }
Advertisement
Add Comment
Please, Sign In to add comment