Search Tutorials

Loading...

Wednesday, 17 April 2013

C code to check a number is Armstrong or not

Armstrong: 
if number is 153 and 13+53+33=153 means sum of the cube of every digit is equal to the given number than is called Armstrong.


C program: 

#include<stdio.h>
 
int Armstrong(int number) 
{
int result = 0;
int remainder; 
while(number != 0)
{
 remainder = number%10;
 result = result + remainder*remainder*remainder;
 number = number/10;
 }

 return result; 
}


void main()
{
int number=153;
int check;
check=Armstrong(number);
if(check==number)
printf("Number iArmstrong");
else
printf("Number is not Armstrong");   
getch();


Output of the above Program:

Check-Armstrong-Number
Check Armstrong Number
 

No comments:

Post a Comment

Back to Top