Pages

Program to check Armstrong number in C

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");
printf("Enter Number : ");
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 !

@msucil

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment