Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int factorial(int n) {
- int fact = 1;
- if (n == 0) {
- return 1;
- }
- else {
- for (int i = 1; i <= n; i++) {
- fact = fact * i;
- }
- return fact;
- }
- }
- int powercalc(int base, int power) {
- int result = 1;
- for (int i = 1; i <= power; i++) {
- result = result *base;
- }
- return result;
- }
- float exponent(int x, int y) {
- float result = 0;
- for (int i = 0; i <= y; i++) {
- result = result + (powercalc(x, i)*1.0 / factorial(i));
- }
- return result;
- }
- int main() {
- int num = 0, n=0;
- float result;
- cout << "Enter the number x to get the result (e^x)!\n";
- cin >> num;
- cout << "Enter the number n that defines how many times you want to run the series!\n ";
- cin >> n;
- result = exponent(num, n);
- cout << "The result after doing the series is " << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement