Skip to content

Instantly share code, notes, and snippets.

@AlexandruFilipescu
Last active June 9, 2019 16:57
Show Gist options
  • Save AlexandruFilipescu/4f0595a3d803e99d547717e3aa1a1ee6 to your computer and use it in GitHub Desktop.
Save AlexandruFilipescu/4f0595a3d803e99d547717e3aa1a1ee6 to your computer and use it in GitHub Desktop.
C++ Se citesc numere intregi de la tastatura pana la intalnirea unui numar negativ. Afisati numarul citit care are cei mai multi divizori(Full numbers are read from the keyboard until a negative number is encountered. Display the read number that has the most divisors.).
#include <iostream>
using namespace std;
int main() {
int a,n,i, nr_afisare, nr_divizori;
nr_divizori = 1;
n = 0;
a = 0;
nr_afisare = 0;
while (n>= 0) {
cin >> n;
for (i = 1; i <= n; i++) {
if (n%i==0) {
a += 1;
}
}
if (a > nr_divizori) {
nr_divizori = a;
nr_afisare = n;
}
a = 0;
}
cout << "numarul cu cei mai multi divizori este: " << nr_afisare << " si are " << nr_divizori<< " divizori";
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment