#include<iostream.h>long fac(long n){long f;if(n<0)cout<<"error!"<<endl;else if(n==0)f=1;else f=n*fac(n-1);return f;}
void main(){long x;cout<<"Please enter the number!"<<endl;cin>>x;cout<<"The result is "<<fac(x)<<endl;}我自己写了个,运行没有问题,你试试看吧!
确实是 其实只要用个 if语句 就好了当时傻了 没想到 还一个人搞了好久