C Program 3 – To check whether a number is Armstrong Number

The armstrong number is of the form 153= 13 + 53 + 33

The input is : 153 or any other number

output: The number is armstrong or not.

Processing: take 153 as an example, remove 3, 5 and 1 in the reverse order (using % operator) and take the power of 3 and add to the sum variable.

if the total sum and the original number, both are same, then that is the arm strong number.

if else, the number is not an armstrong number

#include <stdio.h>
#include <conio.h>

int main()
{
    int original_num, check, temp, sum=0;
    printf("Enter the number to check for armstrong number");
    scanf("%d", &original_num);
// Get the original number
    temp=original_num;
    while(original_num>0)
//run the loop till the number becomes 0
    {
     check=original_num%10; 
//remove the last digit using modulo operator
     sum=sum+check*check*check; //the last digit is taken power to 3 and added to sum
     original_num=original_num/10; //truncate the last digit and run the loop again
     }
     if(sum==temp)
     printf("This is an armstrong number\n");
     else
     printf("This is not an armstrong number \n");
     getch();
     return 0;
}

Comments

  1. Thank u for the all yhe programs which u has attached to ur blog..

    ReplyDelete
  2. Thank you,sir for publishing these programs on your website

    ReplyDelete
  3. Thankyou sir.I WAS FULLY SATISFIED WITH THIS BLOG.:))

    ReplyDelete
  4. i cant understand wat is tis

    ReplyDelete
  5. THANKYOU SIR

    ReplyDelete

Post a Comment

Popular Posts