Testing.

Saturday, 21 January 2017

C programming language: C program to check given number is Armstrong number or not.

 Armstrong number means :-
             Sum of every individual digit's cube value should be equal to that number.
Example:
           153=1^3 + 5^3+ 3^3.
                 =1+125+27
                 =153
-------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int n,num,i,sum=0,rem;
printf("\nEnter Number To Check: ");
scanf("%d",&num);
n=num;
while(num)
{
rem=num%10;
sum=sum+rem*rem*rem;
num =num/10;
}
if(n==sum)
printf("\n%d Is An Armstrong...",n);
else
printf("\n%d Is Not An Armstrong...",n);
getch();
}

No comments:

Post a Comment