求任意一个数的阶乘,怎么写?
我是初学者这是我写的,但错误。whlie(i)这里是不是错的?随便帮我改改!我想好久,明天就上交了。
#include<iostream.h>
void main()
{
int i=1,y=1;
cout<<"请输任意一个数i"<<endl;
cout<<"输入i=";cin>>i;
while(i)
{
y*=i;
i++;
}
cout<<"y="<<y<<endl;
}
[local]1[/local] #include <iostream> using namespace std; int main() { int i,j,k; i=1;j=2; cout<<"请输入任意一个数:"<<endl; cin>>k; for(j=2;j<=k;j++) { i=i*j; } cout<<i<<endl; return 0; }
// Note:Your choice is C++ IDE #include <iostream> using namespace std; static int pi = 1; static int sum = 0; int main() { cout<<"Input the number!"<<endl; int lengthi; cin>>lengthi; for(int i = 1;i <= lengthi;++i) { pi *= i; sum += pi; cout<<"the sum "<<lengthi<<"jie cheng shi:"<<sum<<endl; } return 0; }