0% found this document useful (0 votes)
6 views3 pages

Amstrong Between Two Interval

The document provides a C programming assignment to display Armstrong numbers between two specified intervals. It defines an Armstrong number and includes a sample output for the range of 50 to 600, listing the Armstrong numbers found. Additionally, it presents a complete C code solution that calculates and prints Armstrong numbers within the given range.

Uploaded by

tausif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Amstrong Between Two Interval

The document provides a C programming assignment to display Armstrong numbers between two specified intervals. It defines an Armstrong number and includes a sample output for the range of 50 to 600, listing the Armstrong numbers found. Additionally, it presents a complete C code solution that calculates and prints Armstrong numbers within the given range.

Uploaded by

tausif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MKCL KLiC C Programming

Practice Assignment 22

Write a C Program to display Armstrong Number Between Two Intervals.


A positive integer is called an Armstrong number (of order n) if
abcd... = an + bn + cn + dn +
In the case of an Armstrong number of 3 digits, the sum of cubes of each digit is
equal to the number itself. For example, 153 is an Armstrong number because
153 = 1*1*1 + 5*5*5 + 3*3*3

Enter two numbers(intervals): 50


600
Armstrong numbers between 50 and 600 are: 153 370 371 407

Solution:
#include <math.h>
#include <stdio.h>
int main() {
int low, high, number, originalNumber, rem, count = 0;
double result = 0.0;
printf("Enter two numbers(intervals): ");
scanf("%d %d", &low, &high);
printf("Armstrong numbers between %d and %d are: ", low, high);

// swap numbers if high < low


if (high < low) {
MKCL KLiC C Programming

high += low;
low = high - low;
high -= low;
}

// iterate number from (low + 1) to (high - 1)


// In each iteration, check if number is Armstrong
for (number = low + 1; number < high; ++number) {
originalNumber = number;

// number of digits calculation


while (originalNumber != 0) {
originalNumber /= 10;
++count;
}

originalNumber = number;

// result contains sum of nth power of individual digits


while (originalNumber != 0) {
rem = originalNumber % 10;
result += pow(rem, count);
originalNumber /= 10;
}

// check if number is equal to the sum of nth power of individual digits


if ((int)result == number) {
MKCL KLiC C Programming

printf("%d ", number);


}

// resetting the values


count = 0;
result = 0;
}

return 0;
}

You might also like