Thursday, January 5, 2012

Armstrong number

Q. Write a program to check whether a number is a Armstrong number or not.

Ans.

Definition of Armstrong number: An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.
In other word �A number is Armstrong if it is equal the sum of cube of its digits.�
Example of Armstrong number is 371 because according to definition cube of its digits  sum will be equal to number so
Armstrong number 371=(3)3+(7)3+(1)3
                 371=27+343+1
                 371=371

/*program to check whether a number is Armstrong or not*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int n,num,rem,sum=0;
 printf("Enter any number : ");
 scanf("%d", &num);
 for(n=num; n>=1; n=n/10)
 {
   rem=n%10;
   sum=sum+(rem*rem*rem);
 }
 if(num==sum)
    printf("Number is Armstrong number");
 else
    printf("Number is not Armstrong number");
 getch();
 return 0;
}

Output:-

Enter any number :254
Entered number is not Armstrong number
                   
Enter any number : 371
Entered number is Armstrong number


Related Program:
  1. Amicable number C program
  2. Flowchart for checking number is Armstrong or not
  3. Perfect number C program
  4. Print Armstrong number range C program

No comments:

Post a Comment