forked from Akatakata/zerda-exam-cpp-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04.cpp
More file actions
36 lines (27 loc) · 844 Bytes
/
04.cpp
File metadata and controls
36 lines (27 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//============================================================================
// Name : 04.cpp
// Author : Ak0s
// Description : Exam - task 4
//============================================================================
#include <iostream>
using namespace std;
int divisor_counter(int number);
int main() {
int number;
cout << "Give me a number and I will give you all its divisors: ";
cin >> number;
cout << "The number of divisors of " << number << " is: " << divisor_counter(number);
return 0;
}
int divisor_counter(int number) {
int number_of_divisors;
cout << endl << "The divisors of " << number << " in ascending order are: ";
for (int i = 1; i <= number; i++) {
if (number%i == 0) {
number_of_divisors++;
cout << i << " ";
}
}
cout << endl;
return number_of_divisors;
}