C program to print Armstrong number between 100 and 999?

In this example we will focus on finding and then print Armstrong numbers between the limit from 100 to 999. Before proceeding to our code let’s find out concept Armstrong numbers.

What is called as Armstrong?

Armstrong number is determined based on sum of cube of its digits. If a number equals to addition of cubes of all of its digits then we call it as Armstrong.

Let’s imagine our input is 407 then do the addition of cube of its digits and we get the result as same input that we provided. This is how we determine input is Armstrong or not.

Pre-requisites:

For loop, while loop, input output functions

Approach:

  • First declare required variables for addition, modulo division operation result, cube and division operation result.

  • Run for loop from 100 to 999 and inside for loop assign input to another variable to use it during separation of digits of input number.

  • Run while loop to extract each digit of input.
    Inside while loop, first do modulo division operation on input to find out last digit then store its cube result inside icube variable

  • and then add this cube to isum variable (isum does addition of all cubes)

    and then remove last digit of number by doing division operation on input number by 10.

Program:


Leave a Reply

%d bloggers like this: