Saturday, December 24, 2011

Check Whether Given Number is Armstrong or Not in C Program

It is a sample c program to check whether given number is Armstrong or not.

Program Source Code


#include"stdio.h"
#include"conio.h"
#include"math.h"
void main()
{
int number, a , i , j , sum=0 , count=0;
clrscr();
printf(“Enter any number”);
scanf(“%d”, &number);
i=number;
j=number;
while(j>0)
{
j=j%10;
count++;
}
while(i>0)
{
a=i%10;
sum=sum + pow(a, count);
i=i/10;
}
if(sum==number)
printf(“%d is a Armstrong number”, number);
else
printf(“%d is a not Armstrong number”, number);
getch();
}

Output


Armstrong or Not in C Program

No comments:

Post a Comment

Dont SPAM