Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

from 1 to n how many armstrongs are present; n is an integer.

0 votes
asked Oct 15, 2019 by rinabrata barman (120 points)

1 Answer

0 votes
answered Oct 16, 2019 by anonymous
#include <bits/stdc++.h>

using namespace std;

  

// Prints Armstrong Numbers in given range

void findArmstrong(int low, int high)

{

    for (int i = low+1; i < high; ++i) {

  

        // number of digits calculation

        int x = i;

        int n = 0;

        while (x != 0) {

            x /= 10;

            ++n;

        }

  

        // compute sum of nth power of

        // its digits

        int pow_sum = 0;

        x = i;

        while (x != 0) {

            int digit = x % 10;

            pow_sum += pow(digit, n);

            x /= 10;

        }

  

        // checks if number i is equal to the

        // sum of nth power of its digits

        if (pow_sum == i)

            cout << i << " ";     

    }

}

  

// Driver code

int main()

{

    int num1 = 100;

    int num2 = 400;

    findArmstrong(num1, num2);

    cout << '\n';

    return 0;

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...