Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int prints_dividers(int n)
- {
- if(n == 0)
- return 0;
- cout << 1 << '\t';
- int counter = 1;
- for(int i = 2; i < n; ++i)
- {
- if(n % i == 0)
- {
- cout << i << '\t';
- ++counter;
- }
- }
- if(n > 1)
- {
- cout << n << endl;
- ++counter;
- }
- else
- cout << endl;
- return counter;
- }
- int main()
- {
- cout << "Please enter a number: ";
- int number;
- cin >> number;
- while(cin.fail() || number < 0)
- {
- cout << "You entered the wrong number. Please enter a natural number again: ";
- cin.clear();
- cin.ignore(9999, '\n');
- cin >> number;
- }
- int dividers = prints_dividers(number);
- cout << number << " has exactly " << dividers << " natural dividers.";
- if(dividers == 2)
- cout << " It is a prime number.\n";
- else
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement