Friday , 31 March 2017
Home » Tutorials » C programming » Simple C program to find whether a number is an armstrong number or not

Simple C program to find whether a number is an armstrong number or not

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.

Algorithm:

Step 1: Start
Step 2: Read n
Step 3: Rem=n
Step 4: sum=0
Step 5: If n != 0,
rem=n%0
sum=sum+(rem*rem*rem)
Step 6: n=n/10, goto 5
Step 7: If n=0, then if temp=arm, print Number is armstrong
Step 8: if temp is not equal to arm print Number is not armstrong
Step 9: Stop

Program : 

#include 
int main()
{
   int number, sum = 0, n, rem;
   printf("Enter a number\n");      
   scanf("%d",&number);
   n = number;

   while( n != 0 )
   {
      rem = n%10;
      sum = sum + rem*rem*rem;
      n = n/10; 
   }

   if ( number == sum )
      printf("Entered number is an armstrong number.");
   else
      printf("Entered number is not an armstrong number.");         

   return 0;
}

About Rajeel

I'm Rajeel, a teen blogger from India who loves computers, sports, internet and all other kind of tech stuffs. This blog thing is one of my favourite hobby and the one that eats up much of my time. But Really, I'm loving it :) Find me in G+

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Scroll To Top