I need help

I need help with a “simple” algoritm i need to find the largest divisor of a custom number for example if i take 21 i get in return 7. i Can only show all of divisors but dont know how to point the largest one ;/


using namespace std;

int main(){
    int n, i;

    printf("Enter a number: ");

    for(i=1;i<=n;i++) {

        if(n%i==0 && n!=i){




    return 0;

You could start at n and work down, and have your program stop as soon as you find a divisor. (The first one will be the largest).

i = n - 1
for loop
   some code
   i -= 1