#hello guys, im new to cpp. can someone help me to find out what does this program do?

1 messages · Page 1 of 1 (latest)

burnt acorn
#
using namespace std;
int main() {
    int numdes, maxnull = 0, numberofnull = 0, maxnumdes = 0;
    bool T = true;
    cin >> numdes;
    int Z;
    int Y;
    int y = numdes;
    for (int n = 1; n <=numdes; n++) {
        Z = n;
        T = false;
        for (int i = 2; i < n; i++) {
            if (n % i == 0) {
                T = true;
                break;
            }
        }
        if (T) continue;
        while (Z != 1) {
            if (!(Z % 2)) {
                numberofnull++;
                Z /= 2;
            }
            else {
                Z = (Z - 1) / 2;
            }
        }
        if (numberofnull >= maxnull) {
                maxnull = numberofnull;
                maxnumdes = n;
            }

        numberofnull = 0;
    }
    cout << maxnumdes << endl;
}
urban loomBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

finite bramble
#

well if you wrote it, you should know what it does and if it's from somewhere else. is there no explanation there?

burnt acorn
finite bramble
#

not realy with this amouth of information

burnt acorn
burnt acorn
tribal creek
#

It's open AI chatgpt

#

The result of this question is amazing

burnt acorn
#

and thank you very much

tribal creek
#

The program first prompts the user to enter a positive integer, which is stored in the variable numdes. This integer represents the number of integers that the user wants to test.

Next, the program initializes several variables: maxnull, numberofnull, maxnumdes, and T. The variable maxnull will be used to store the maximum number of times the number is divided by 2, numberofnull will be used to count the number of times the number is divided by 2, maxnumdes will be used to store the maximum prime number found, and T will be used as a flag to determine whether a number is prime or not.

The program then enters a loop that iterates numdes times. For each iteration, the program first checks if the current number is prime. If the number is not prime, the program skips the rest of the loop and continues to the next iteration. If the number is prime, the program enters another loop that divides the number by 2 as long as the number is even (divisible by 2). For each division by 2, the program increments the numberofnull variable. When the number becomes odd (not divisible by 2), the program divides the number by 2 and subtracts 1, then continues the loop.

After the inner loop finishes, the program compares the value of numberofnull with the value of maxnull. If numberofnull is greater than or equal to maxnull, the program updates maxnull and maxnumdes with the values of numberofnull and the current number, respectively. Finally, the program resets the numberofnull variable to 0 and continues to the next iteration of the outer loop.

After the outer loop finishes, the program prints the value of maxnumdes, which is the largest prime number that was found.```
burnt acorn
tribal creek
#

oh

#

sad

#

Anyway there u got

#

A very in depht explanation ✅

burnt acorn
#

!solved