阶乘图面的改进
要求在每次调用中,在单独的一行中显示输入结果并且增加一级缩进#include<iostream>
#include<iomanip>
using namespace std;
unsigned long jiecheng(unsigned long);
int main()
{
for(int counter=0;counter<=10;counter++)
{
cout<<setw(2)<<counter<<"!="<<endl;
int count=5,num=counter;
while(num>=2&&num<=10)
{
cout<<setw(count)<<num<<"*"<<num-1<<"!"<<endl;
count+=2;
num--;
}
cout<<setw(count+2)<<"="<<jiecheng(counter)<<endl;
}
system("pause");
}
unsigned long jiecheng(unsigned long number)
{
if(number<=1)
{
return 1;
}
else
{
return number*jiecheng(number-1);
}
}