Pages

Tuesday, November 10, 2015

C Program For Armstrong no.

/*
A positive integer is called an Armstrong number if the sum of cubes of individual digit is equal to that number itself. For example:
153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
12 is not equal to 1*1*1+2*2*2  // 12 is not an Armstrong number.
*/

Program

#include<stdio.h>
void main()
{
int no,rem,sum=0,temp;
printf("\nEnter the number ");
scanf("%d",&no);
temp=no;
while(no!=0)
{
rem=no%10;
sum=sum+rem*rem*rem;
no=no/10;
}

if(temp==sum)
printf("%d is an armstrong number.\n",temp);
else
printf("%d is not an armstrong number.\n",temp);
}

Output

Enter the number 153
153 is an armstrong number.

No comments:

Post a Comment