Display Armstrong Number Between Two Intervals

Write a program to Display Armstrong Number Between Two Intervals.

Armstrong Number: Armstrong number is a number that is equal to the sum of cubes of its digits. For Example, 153 is Armstrong number, 1^3+3^3+5^3=153.

C Program

#include <stdio.h>
#include <math.h>

int main()
{
    int startend;
    printf("Enter a starting number : ");
    scanf("%d", &start);

    printf("Enter a ending number : ");
    scanf("%d", &end);

    printf("Armstrong number from %d to %d are:\n"startend);
    for (int i = starti <= endi++)
    {
        int n = i;
        int sum = 0;
        while (n > 0)
        {
            int temp = n % 10;
            sum = sum + pow(temp3);
            n = n / 10;
        }
        if (sum == i)
        {
            printf("%d "i);
        }
    }
    return 0;
}
Input:
Enter a starting number : 10
Enter a ending number : 500

Output:

Armstrong number from 10 to 500 are:
153 370 371 407 


No comments:

Post a Comment