Advertisement
jasonpogi1669

Divisors of 'n' using C++

Aug 19th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void Divisors(int n) {
  6.     for (int i = 1; i <= (int) sqrt(n); i++) {
  7.         if (n % i == 0) {
  8.             if (n / i == i) {
  9.                 cout << i;
  10.             } else {
  11.                 cout << i << " " << n / i << " ";
  12.             }
  13.         }
  14.     }
  15. }
  16.  
  17. int main() {
  18.     int n;
  19.     cin >> n;
  20.     Divisors(n);
  21.     return 0;
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement