What is Armstrong Number?
Armstrong number is a number that is equal of sum of cubed of its digits.
as a example - 153= 13 + 53 + 33 =1+125+27=153

Source Code:

  1.       # include <stdio.h>
  2.     
  3.        int main()
  4. {
  5.    int temp,n,sum=0,x;
  6.    printf("Enter the number: ");
  7.    scanf("%d",&x);
  8.    temp=x;
  9.    while(temp>0)
  10.     {
  11.     n=temp%10;
  12.     sum=sum+(n*n*n);
  13.     temp=temp/10;
  14. }
  15.    if(sum==x)
  16.    printf("\n It is an anstrong number!!!");
  17.    else
  18.    printf("\n It is not an anstrong number!!!");
  19.    
  20.        return 0;
  21. }

Output:

Enter the number: 153

 It is an anstrong number!!!

Enter the number: 123

 It is not an anstrong number!!!

0 comments:

Post a Comment