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.

Need help with a c++ exercise

+8 votes
asked Jan 14 by Ascentrix X (200 points)
I need to write a program in C++ that determines the biggest power that a number appears to in the prime factorization of an "n" number.

What I did so far:

#include <iostream>

using namespace std;

int main()
    int n, d = 2, p;
    cin >> n;
    while(n != 1)
        p = 0;
        while(n % d == 0)
            n = n / d;
        if(p > 0)
            cout << d << " to the power of " << p << endl;

    return 0;

1 Answer

0 votes
answered Jan 27 by Peter Minarik (89,230 points)
So far so good.

You just need to remember the highest p and d pars and print only these at the end.

Do you have any questions?

Good luck!
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.