Power and Factorial

My program basically asks the users for a value (s) then calculates and displays the First, Middle, Last, and Final. The users have a choice to enter the value either in integer, real or character. If the user enters it in real or character, it will be converted into integer value before the required value is computed. I have written the power , factorial and the sigma functions which I will use in calculating the first, middle and the last. Can somebody assist in checking my codes to see if its correct and show how I will those functions to calculate the first and the last which a bit more complicated?

First = X^1/1! - X^3/3! + X^5/5! - X^7/7! + X^9/9! - ....X^n/n!
Middle = n sigma i = 1 sqrt(i/x)
last = 1- X^2/2! + X^4/4! - X^6/6! + X^8/8! - ....X^n/n!
Final = first/last + middle

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include<cmath>
using namespace std;


int powerfunc (int x, int n)
{
  int x, n;
  int  p, i;
while (i <=n)
 {
   p = p * x;
   i = i + 1;
   return p;
 }
}

int factorial (int n)
{
   int i, n;
   int f = 1;
for (i = 1; i <= f; i++)
  {
      f *= i;
     return f;
    }
}

int sigma(int x, int n)
{
   int i = 1, sum = 0;
   int x, n;
while (i <= n)
  {
     sum += i *  i;
      i++;
     sum = sqrt(sum/x)
      return sum;
    }
}

int main()
{
   
  int x, n;
  int first, middle, last, final;
cout << “Please enter the value for x” << endl;
cin >> x;
cout << “Please enter the value for n” << endl;
cin >>n;

 middle = sigma(x, n)
 final = fist/(last + middle);

 cout << “The value for first is << first << endl;
 cout << “The value for middle is << middle << endl; 
 cout << “The value for last is << last << endl;
 cout << “The value for final is << final << endl;







return 0;
}
Last edited on
Please use code tags for more than a couple lines of code.
Topic archived. No new replies allowed.