A positive integer is called an Armstrong number if the sum of cubes
of individual digit is equal to that number itself.
For example:
Enter a positive integer: 371
371 is an Armstrong number.
For example:
153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number. 12 is not equal to 1*1*1+2*2*2 // 12 is not an Armstrong number.
Source Code to Check Armstrong Number
/* C program to check whether a number entered by user is Armstrong or not. */
#include <stdio.h>
#include <conio.h>
void main()
{
int n, n1, rem, num=0;
clrscr();
printf("Enter a positive integer: ");
scanf("%d", &n);
n1=n;
while(n1!=0)
{
rem=n1%10;
num+=rem*rem*rem;
n1/=10;
}
if(num==n)
printf("%d is an Armstrong number.",n);
else
printf("%d is not an Armstrong number.",n);
}
OutputEnter a positive integer: 371
371 is an Armstrong number.
No comments:
Post a Comment