/* This is HW4_4 Lab EE107
The purpose of this function to calculate exponential function with power notation
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Due Date: April 26th, 2024.
*/
#include <stdio.h>
// Function to calculate x raised to the power of n
long int x_to_the_n_EU(int x_EU, int n_EU) {
// Base case: if n is 0, return 1
if (n_EU == 0)
return 1;
// Initialize the result to 1
long int result_EU = 1;
// Iterate n times and multiply result by x in each iteration
for (int i_EU = 0; i_EU < n_EU; i_EU++) {
result_EU *= x_EU;
}
// Return the result
return result_EU;
}
int main() {
int x_EU, n_EU;
// Prompt user to enter the base (x)
printf("Enter the base (x): \n");
scanf("%d", &x_EU);
// Prompt user to enter the exponent (n)
printf("Enter the exponent (n):\n ");
scanf("%d", &n_EU);
// Calculate x raised to the power of n
long int result_EU = x_to_the_n_EU(x_EU, n_EU);
// Print the result
printf("\n%d raised to the power of %d is %ld\n", x_EU, n_EU, result_EU);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: