26 December 2011

C Program to find whether a Given Number is Armstrong Number or not

3 comments


Program to Check Whether a Number is Armstrong Number or not


#include<stdio.h>

//declaration of function
int arm(int);

void main()
{
int a,b;
printf("enter the number: ");
scanf("%d",&a);
b = arm(a);
if(b==a)
printf("the entered number is armstrong");
else
printf("the given number is not armstrong");
}
//definition of function to check a number for Armstrong Number
int arm(int x)
{
int b = 0,a = 0;
while(x>0)
{
a = x%10;
b +=a*a*a;
x = x/10;
}
return b;
}

If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

3 comments: