Instructions
Requirements and Specifications
Source Code
#include
void read_input(int &x, int &y) {
std::cout << "Enter integer: ";
std::cin >> x;
std::cout << "Enter power: ";
std::cin >> y;
}
int power(int x, int n) {
int y = 1;
for(int i = 0; i < n; i++){
y = y*x;
}
return y;
}
int factorial(int x, int &result) {
result = 1;
for(int i = 1; i <= x; i++) {
result *= i;
}
return x;
}
void print_results(int x, int n) {
// First, calculate the power
int pow = power(x, n);
// Define variable to store result of factorial
int facto;
factorial(x, facto);
// Now, print
std::cout << "The " << n << "-th power of " << x << " is: " << x << "^" << n << " = " << pow << std::endl;
std::cout << "The factorial of " << x << " is: " << x << "! = " << facto << std::endl;
}
int main() {
// define variables
int x, n;
// read input from user
read_input(x, n);
// Print results
print_results(x, n);
}