forked from jeremie1112/hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCpluspluscode.txt
More file actions
41 lines (36 loc) · 767 Bytes
/
Cpluspluscode.txt
File metadata and controls
41 lines (36 loc) · 767 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
31
32
33
34
35
36
37
38
39
40
<h1>Program about factorials
#include <iostream>
using namespace std;
float factorialN(int n){
if (n == 1 || n == 0){
return 1;
}
else{
return(n * factorialN(n-1));
}
}
float XpowerN(float x,int n){
if (n == 0){
return 1;
}
else{
return(x * XpowerN(x,n-1));
}
}
float powerpertorial(float x, int n){
return (XpowerN(x,n)/factorialN(n));
}
int main(){
int b
float a, calculate;
cout<<"Input float a and integer b : /n"
cin>>a>>b;
while(a<0 && b<0){
cout<<"There is an error"<<endl;
cout<<"Reinput float a and integer b : "<<endl;
cin>>a>>b;
}
calculate = powerpertorial(a,b);
cout<<"a^b / b! is : "<<calculate<<endl;
return 0;
}