Programme to Check whether a number is an Armstrong number
Here you will know how to Check whether a number is an Armstrong number or not .
In this method we have used a while loop to check for an Armstrong number.I have also attatched the screenshots of the programme I have written and the generated output.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num,r,result,sum=0,temp;
printf("Enter a number");
scanf("%d",&num);
temp=num;
while(temp!=0)
{
r=temp%10;
sum=sum+r*r*r;
temp=temp/10;
}
if(num==sum)
printf("The entered number is an Armstrong number");
else
printf("The entered number is not an Armstrong number");
return 0;
}
The screenshot is:
The generated output is:
Comments
Post a Comment