C Program to accept a number and check the given number is Armstrong or not


/*153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.*/
#include<stdio.h>
#include<conio.h>
main( )
{
int number, originalNumber, remainder, result = 0;
clrscr( );
printf (" Enter a Three Digit Number:");
scanf ("%d", &number);
originalNumber=number;
while(originalNumber!=0)
{
remainder=originalNumber%10;
originalNumber=originalNumber/10;
result=result+remainder*remainder*remainder;
}
if (result==number)
printf ("The Given Number is Armstrong number");
else
printf ("The Given Number is Not Armstrong number");
getch( );
}

Output:

Run-1

Run-2




No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...