Write a c program to Check whether a number is a AMSTRONG NUMBER or not.


source code:


  1. #include<stdio.h>

  2. void main()
  3. {
  4.   int n,sum=0,digit,t;
  5.   
  6.   printf("Enter any integer number:");
  7.   scanf("%d",&n);
  8.   t=n;
  9.   while(n!=0)
  10.    {
  11.      digit = n%10;
  12. sum = sum + digit * digit * digit;
  13.      n=n/10;     
  14.    }
  15.   
  16.   //printf("The sum of its digit is:%d\n",sum);
  17.   printf("\n");
  18.     if(sum==t)
  19.      printf("It is an Amstrong number.");
  20.     else
  21.      printf("It is not an Amstrong number.");
  22.    
  23. }

Output:

1st example:


Enter any integer number:371

It is an Amstrong number.

2nd example:

Enter any integer number:125

It is not an Amstrong number.

0 comments:

Post a Comment