Write a subprogram that calculates n!. While using this subprogram make a program that calculates (a+b)!
Ok, so there's my code I and the error it gives me. Can't find a way to fix that, thanks for the help in advance!
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;
Error :
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
Aucun commentaire:
Enregistrer un commentaire