Wednesday, 8 January 2014

Check give number is Armstrong or not

Armstrong program in C

Armstrong number program in C is easy and simple to write, suppose we take any three digits number and check number is armstrong or not; first find cube of all digits and find sum of all digits if sum is equal to number then that number is armstrong number.


#include<stdio.h>
#include<conio.h>
void main()
{
int arm=0,a,b,c,d,no;
clrscr();
printf("Enter any num = ");
scanf("%d",&no);
d=no;
while(no>0)
{
a=no%10;
no=no/10;
arm=arm+a*a*a;
}
if(arm==d)
{
printf("\n%d armstrom",no);
}
else
{
printf("not");
}
getch();
}


Output

Armstrom

Armstrom

No comments:

Post a Comment