Armstrong number is a number that is equal to the sum of cubes of the same digit. For e.g. 0, 1, 153, 370, 371, and 407 are the Armstrong numbers. 153 = (1*1*1)+ (5*5*5)+ (3*3*3)
Flowchart
Problem
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
int no, copy, rem, n = 0, ans = 0;
printf("enter a value of no: ");
scanf("%d", &no);
copy = no;
while (copy != 0)
{
copy = copy / 10;
n++;
}
copy = no;
while (copy != 0)
{
rem = copy % 10;
ans = ans + pow(rem, n); // subsisting the power with n's value
copy = copy / 10;
}
if (ans == no)
{
printf("%d is armstrong number!", no);
}
else
{
printf("%d is not an Armstrong number!", no);
}
getch();
}
output
enter a value of no: 407
407 is an Armstrong number!
0 Comments