I need help

java

#1

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 ;/

#include<iostream>
#include<cstdlib>

using namespace std;


int main(){
    int n, i;

    printf("Enter a number: ");
    cin>>n;


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

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

            cout<<"divisors"<<i;

        }

    }

    return 0;
}

#3

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