In This program user ask to find out the number is Armstrong or not. “A number is Armstrong if the sum of cubes of individual digits of a number is equal to the number itself”. User declares required variables for this operation. User uses a temp variable that will use to store the value for temporary time period. Declaring while condition while (num>0) user ask to cub=num%10, num=num/10, sum=sum+ (cub*cub*cub).
Then a if-else condition if(temp==sum) then the number is Armstrong else it will not. And after creating all instance in the end display result on the screen as output.
Problem statement:
This is C program to Check out the Number is Armstrong or not.
- Declaring the variables.
- Using while condition along with control statements.
- Display result on the Screen.
Here is C source code for checking out the number is Armstrong or not. The output of this program shown below.
#include<stdio.h>
void main()
{
int num,temp,cub,sum=0;
clrscr();
printf("Enter a Number : ");
scanf("%d",&num);
temp=num;
while(num>0)
{
cub=num%10;
num=num/10;
sum=sum+(cub*cub*cub);
}
if(temp==sum)
printf("Number is Armstrong");
else
printf("Number is not Armstrong");
getch();
}
Output :