Tuesday 8 April 2014

c program for given number is Armstrong or not

Definition:
sum of cubes of digits of a number is equal to given number is called Armstrong Number

#include<stdio.h>
void main()
{
int number,temp,sum=0,rem;

printf("nEnter Number For Checking Armstrong : ");
scanf("%d",&number);

temp = number;

 while (number != 0)
 {
  rem = number % 10;
  sum = sum + (rem*rem*rem);
  number = number / 10;
 }

if(temp == sum)
    printf("n%d is Amstrong Number",temp);
else
    printf("n%d is Amstrong Number",temp);
getch();
}

No comments:

Post a Comment