Sunday, December 15, 2019

Write a program to check Armstrong Number or not.

About:
A positive integer is called an Armstrong number (of order n) if
abcd...=an+bn+cn+dn+.....
In the case of an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself. For example, 153 is an Armstrong number because
153=1*1*1+5*5*5+3*3*3

Program:
#include<stdio.h>
void main()
{
int a,n,s=0,l;
printf("Enter any three-digit no:");
scanf("%d",&n);
int b=n;
while(n){
a=n%10;
s=s+(a*a*a);
n=n/10;
}
if(b==s)
printf("Given number is Armstrong");
else
printf("Not Armstrong number");
}

No comments:

Post a Comment

Write a program to find gcd of two numbers using recursion.

About:  The process in which a function calls itself is called recursion and the corresponding function is called as recursive function. ...