Guys..I'm trying to understand this coding and I can't understand the for loop. Can someone please explain it to me what happened there. Thank you

#include <iostream>
using namespace std;

int main()
{
    long long int number;

    cout << "Enter number to test: ";
    cin >> number;

    for(int x=2; x<(number/2); x++)
    {
        while(number%x==0)
            number/=x;
    }

    cout << '\nLargest Prime: ' << number << '\n';
    return 0;
}
Dave Sinkula commented: The forum is for questions, snippets are for posting tutorial-ish code. -2

for(int x=2; x<(number/2); x++) Start a loop from 2 to number/2, incremented by 1
If number is 10, loop through 2,3,4, { while(number%x==0) Another loop -- when the remainder of number/x is zero exit the loop number/=x; Divide number/x giving a new number }

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.