/* THE GIVEN NUMBER IS ARMSTRONG NUMBER OR NOT */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,a,sum=0,temp;
clrscr();
printf("Enter a number: ");
scanf("%d",&n);
temp=n;
while(n>0)
{
a=n%10;
sum=sum+(a*a*a);
n=n/10;
}
if(sum==temp)
printf("%d is an Armstrong number",temp);
else
printf("%d is not an Armstrong number",temp);
getch();
}
Sample output:
Enter a number: 153
153 is an Armstrong number
EXAMPLE 1: 153
TOTAL DIGITS IN 153 IS 3
AND 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
#include<stdio.h>
#include<conio.h>
void main()
{
int n,a,sum=0,temp;
clrscr();
printf("Enter a number: ");
scanf("%d",&n);
temp=n;
while(n>0)
{
a=n%10;
sum=sum+(a*a*a);
n=n/10;
}
if(sum==temp)
printf("%d is an Armstrong number",temp);
else
printf("%d is not an Armstrong number",temp);
getch();
}
Sample output:
Enter a number: 153
153 is an Armstrong number
EXAMPLE 1: 153
TOTAL DIGITS IN 153 IS 3
AND 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
No comments:
Post a Comment