Check Whether The Number Is Armstrong or Not?
Armstrong number program in C
#include<stdio.h>
#include<conio.h>
int power(int, int);
void main()
{
int n, sum = 0, t, remainder, digits = 0;
{
int n, sum = 0, t, remainder, digits = 0;
printf("Input an integer\n");
scanf("%d", &n);
scanf("%d", &n);
t = n;
// Count number of digits
while (t != 0) {
digits++;
t = t/10;
}
// Count number of digits
while (t != 0) {
digits++;
t = t/10;
}
t = n;
while (t != 0) {
remainder = t%10;
sum = sum + power(remainder, digits);
t = t/10;
}
remainder = t%10;
sum = sum + power(remainder, digits);
t = t/10;
}
if (n == sum)
printf("%d is an Armstrong number.\n", n);
else
printf("%d isn't an Armstrong number.\n", n);
printf("%d is an Armstrong number.\n", n);
else
printf("%d isn't an Armstrong number.\n", n);
getch();
}
}
int power(int n, int r) {
int c, p = 1;
int c, p = 1;
for (c = 1; c <= r; c++)
p = p*n;
p = p*n;
return p;
}
}
No comments:
Post a Comment