Last active
November 24, 2023 11:12
-
-
Save iahmadgad/1793797b03089509f9424ae1f5d710d8 to your computer and use it in GitHub Desktop.
C++ divisors printer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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