About Armstrong number:
1. Write a C-program to print Armstrong number up to 1000:
Code:
#include<stdio.h>
void main()
{
int i,j,k,s;
printf("The amstrong number are:\n");
for(i=1;i<=1000;i++)
{
j=i;
s=0;
while(j!=0)
{
k=j%10;
s=s+k*k*k;
j=j/10;
}
if(s==i)
printf("%d\n",i);
}
}
Output:
2. Write a C-Program to Check the number is Armstrong number or not:
Code:
#include<stdio.h>
void main()
{
int n,a,b=0,m;
printf("Enter a number:\n");
scanf("%d",&m);
n=m;
while(n!=0)
{
a=n%10;
n=n/10;
b=b+a*a*a;
}
if(b==m)
printf("\nArmstrong number!!");
else
printf("Not Armstrong number!!");
}
Output:
Comments
Post a Comment
Give your feedback!
DO NOT SPAM !!
NO THIRD PARTY PROMOTIONAL LINK !!!! (else comment will be deleted.)