The number whose sum of the cube of each digit is equal to the number is called Armstrong number. This program show you how to calculate and determine Armstrong number in C.
Source Code:
#include <stdio.h>
#include <conio.h>
void main()
{
int num, temp, rem, sum = 0;
printf("Program to check Armstrong Number! \n");
scanf("%d", &num);
temp = num;
while(temp != 0)
{
//get last digit/reminder
rem = temp % 10;
sum += (rem * rem * rem);
//remove last digit
temp = temp / 10;
}
if(sum += num)
printf("%d is Armstrong Number!", num);
else
printf("%d is not Armstrong Number!", num);
getch();
}
Output:
Program to check Armstrong Number!
Enter Number : 371
371 is Armstrong Number !
No comments:
Post a Comment