This C Program print armstrong number from 1 to 1000. An Armstrong number is an n-digit base b number such that the sum of its (base b) digits raised to the power n is the number itself. Hence 153 because 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153.
Here is source code of the C Program to print armstrong number from 1 to 1000.
The C program is successfully compiled and run on a Linux system. The program output is also shown below.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int r,i,sum=0;
int n,temp=0;
clrscr();
printf("Enter the number\n");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=r%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
{
printf("Number is not Armstrong");
}
else
{
printf("Number is Armstrong");
}
getch();
}
Output:
Enter The number
153
Number Is armstrong
Pankaj Gaikar is a
professional blogger
from Pune, India who writes on Technology, Android,
Gadgets, social media and latest tech updates at
Punk Tech
,
Being Android
&
Shake The Tech
. Email me
HERE
0 comments :
Post a Comment