Skip to content

Instantly share code, notes, and snippets.

@iahmadgad
Last active November 24, 2023 11:12
Show Gist options
  • Save iahmadgad/1793797b03089509f9424ae1f5d710d8 to your computer and use it in GitHub Desktop.
Save iahmadgad/1793797b03089509f9424ae1f5d710d8 to your computer and use it in GitHub Desktop.
C++ divisors printer
#include <iostream>
#include <string>
using namespace std;
void printDivisors(long l);
int main()
{
long n;
cin >> n;
printDivisors(n);
}
void printDivisors(long l)
{
cout << 1 << ", " << l;
for(long i = 2; i * i <= l; i++)
{
if(i * i == l) cout << ", " << i;
else if(l % i == 0) cout << ", " << i << ", " << l / i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment