Find Armstrong number: C Program

0
2043

An Armstrong number is an n-digit number that is equal to the sum of the nth powers of its digits. In this lesson, students will explore Armstrong numbers, identify all Armstrong numbers less than 1000, and investigate a recursive sequence that uses a similar process. Throughout the lesson, students will use spreadsheets or other technology.

Explain to students that they will be implementing the following process for several numbers:

  1. Raise each digit to a power equal to the number of digits in the number. For instance, each digit of a four‑digit number would be raised to the fourth power; each digit of a five‑digit number would be raised to the fifth power; and so on.
  2. Add the results.

Demonstrate this process for 123—because 123 is a three-digit number, raise each digit to the third power, and add: 13 + 23 + 33 = 36. If necessary, show other examples. Then, have students implement the process for the following numbers:

6       23     99    231       1634      11,111

Students are likely to notice that two numbers from this list—6 and 1634—return their original value when this process is applied; that is, 61 = 6, and 14 + 64 + 34 + 44 = 1634.

Inform students that numbers which return their original value are known as Armstrong numbers. Once you are certain that all students understand this idea, allow them to work in pairs to create a succinct definition of Armstrong numbers. After a few minutes, have each group share their definition with another pair, and then allow the class to vote on which definition is most lucid and precise. For comparison, share the following formal definition:

 Armstrong number: An n-digit number equal to the sum of the nth powers of its digits.

Finding Armstrong Numbers

In examining the numbers above, students found that 6 and 1634 were Armstrong numbers. Now ask them to determine all Armstrong numbers less than 1000.

[message_box title=”Program” color=”red”]

/* C program to check whether a number entered by user is Armstrong or not. */

/* Written by Utpal Chaudhary */

/*Student of L.D COLLEGE OF ENGINEERING,Ahmedabad-15,Gujarat */

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

void main()
{
int num, temp, remainder, sum=0;
printf (“Enter a positive integer= “);
scanf (“%d”, &num);
temp=num;
while(num > 0)
{
remainder=n1%10;
sum =sum + (remainder * remainder * remainder);
num=num/10;
}
if(sum==temp)
{
printf(“%d is an Armstrong number.”,temp);
}
else
{
printf(“%d is not an Armstrong number.”,temp);
}
getch();

}

[/message_box]

[message_box title=”Output 1″ color=”red”]
Enter a positive integer=153

153 is an Armstrong number.
[/message_box]

[message_box title=”Output 2″ color=”red”]
Enter a positive integer=55

55 is not an Armstrong number.
[/message_box]

[message_box title=”” color=”yellow”]

Note :If you want to check n digit positive integer number is Armstrong or not Armstrong then in place of 3 times multiplication of remainder take n times multiplication of remainder in above program.

[/message_box]

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments