In this example, we are going to make a C program to check Armstrong’s number. For this, we add the cubes of all the digits of the number entered by the user. If the sum is equal to the number entered by the user then it is an Amstrong number.
Enter Number: 370
it is an Armstrong number.
C program to check Armstrong number
#include<stdio.h>
#include<conio.h>
void main()
{
int num,r,x,sum=0,i;
clrscr();
printf("n Enter Number:");
scanf("%d",&num);
i=num;
while(i>0)
{
r=i%10;
x=r*r*r;
sum=sum+x;
i=i/10;
}
if(num==sum)
printf("nIt is Armstrong number");
else
printf("n It is not Armstrong number");
getch();
}
What is Armstrong number?
The sum of the cubes of all the digits of the number is equal to the number then it is an Armstrong number.
C++ program to check Armstrong number
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int num,r,x,sum=0,i;
cout<<“n Enter Number:";
cin>>num;
i=num;
while(i>0)
{
r=i%10;
x=r*r*r;
sum=sum+x;
i=i/10;
}
if(num==sum)
cout<<"n It is Armstrong number";
else
cout"n It is not Armstrong number";
return 0;
}
Thanks for reading the C program to check Armstrong’s number & the C++ program to check Armstrong’s number.
Show Comments