📄 dashu.cpp
字号:
#include<iostream.h>
#include"SeqList.h"
#include<windows.h>
void main(void)
{
SeqList<int> a(1);
int w,s; //格式化输出计数,for循环计数用
int carry;
cout<<"请输入一个整数::w=";
cin>>w;
if(w<0)
{
cout<<"输入数据错误!\n";
return;
}
DWORD Time1 = GetTickCount();
a.Insert(1);
for(s=1;s<=w;s++)
{
carry=0;int i=0,q,k,m;
for(;a.Find(i,k);)
{
q=k*s+carry;
carry=q/10;
q=q%10;
a.Update(i,q); i++;
}
while(carry>0) //排除carry是大于9的数却被直接加到高位的情况
{
m=carry%10;
carry=carry/10;
a.Insert(m);
}
if(carry>0) a.Insert(carry); //判断carry是否仍然大于0
}
a.Reverse();
cout<<w<<"的阶乘为: \n";
a.Output(cout);
DWORD Time=GetTickCount()-Time1;
cout<<endl<<Time<<"ms"<<endl;
} //统计计算的时间 为 毫秒
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -