My task is
Write a subprogram that calculates
n!
. While using this subprogram make a program that calculates(a+b)!
.
I wrote the following code:
using namespace std;
int f(int n) {
for(int i=1;i<=n;i++){
f=f*i;
}
return f;
}
int main() {
int a,b;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"factorial of a+b="<<(a+b)*f;
return 0;
}
And I get this error when I compile:
In function 'int f(int)':
7:27: error: invalid operands of types 'int(int)' and 'int' to binary 'operator*'
8:8: error: invalid conversion from 'int (*)(int)' to 'int' [-fpermissive]
In function 'int main()':
16:34: error: invalid operands of types 'int' and 'int(int)' to binary 'operator*'
17:9: error: expected '}' at end of input