Program to print the 3 digits Armstrong number.
Armstrong number is a number whose sum of digits raised power number of digits will be equal to that number so this number is called as Armstrong number. 153 =1³+5³+3³=153
Code for the Armstrong Number
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum,r,cube,num;
printf("Armstrong numbers are\n");
for(num=100;num<999;num++)
{
n=num;
sum=0;
while(n>0)
{
r=n%10;
cube =r*r*r;
sum=sum+cube;
n=n/10;
}
if(num==sum)
printf("%d\n", num);
}
getch();
}
Output
When we run the program the output will be all the Armstrong numbers whose sum of digits raised power numbers of digits is equal to that number. For e.g 153 is an Armstrong no. 1³+5³+3³= 153. Where Power ³ is the no. of digits of the number.
Conclusion.
This program is solely written and published by Irfan Ahanagar. Please give me feedback if this helpful to you or not . And if you find any mistake then please comment down.
0 Comments