-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis the factor is base.cpp
More file actions
30 lines (24 loc) · 941 Bytes
/
is the factor is base.cpp
File metadata and controls
30 lines (24 loc) · 941 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
#include <iostream>
using namespace std;
bool checkForFactor(int base, int factor)
{
return (factor != 0 && base % factor == 0); // Check if factor is not zero and if it divides base evenly
// If factor is zero, it cannot be a factor of any number, hence return false
// If base % factor equals zero, it means factor is a factor of base, hence return true
// If base % factor does not equal zero, it means factor is not a factor of base, hence return false
}
int main()
{ int base, factor;
cout << "Enter the base number: ";
cin >> base;
cout << "Enter the factor number: ";
cin >> factor;
bool result = checkForFactor(base, factor);// Call the function to check if factor is a factor of base
if(result) {
cout << factor << " is a factor of " << base << endl;
} else
{
cout << factor << " is not a factor of " << base << endl;
}
return 0;
}