Recursive C Program:
Aim:To find given number is Armstrong Number or Not.
Program:
#include<stdio.h>
int armn(int n)
void main()
{
int num,res;
printf("Enter the number:\n"); scanf("%d",&num);
res=armn(num);
if(num==res)
printf(" \n%d is an Armstrong number ",num);
else
printf("\n%d is NOT an Armstrong number",num);
}
int armn( int n)
{
int arms=0,rem;
while(n>0)
{
rem=n%10; arms=arms+(rem*rem*rem); n=n/10;
}
return ( arms) ;
}
Output:
Enter the Number: 121
121 is NOT an Armstrong number
Click Here to view programs list
No comments:
Post a Comment