In this program, the while loop is used. The Armstrong number starts from 0, 1, 153, 370,... and so the mathematical formula is used in this program, Also while loop and if else is used together in this program.
Basically , armstrong no. are the ones whose cube of individual digits when added it gives back the no. .
For eg :- no. is 153 ...1^3 + 5^3 + 3^3 = 153 itself
Basically , armstrong no. are the ones whose cube of individual digits when added it gives back the no. .
For eg :- no. is 153 ...1^3 + 5^3 + 3^3 = 153 itself
Program to check Armstrong Number.
#include<stdio.h>#include<conio.h>
void main()
{ int a=0,n=0,sum=0,m=0;
clrscr();
printf("To check whether no. is armstrong or not");
printf("\n\n\t enter the no. to check : ");
scanf("%d",&n);
n = m;
while(n>0)
{ a = n%10;
sum = sum + a*a*a;
n = n/10;
}
if(sum==m)
{ printf("\n\n\t no. is armstrong");
}
else printf("\n\n\t no. is not armstrong");
getch();
}

No comments:
Post a Comment
Guys if you think something is wrong or should be edit than please do comment.