#17268: 這樣有錯媽


Easonsfriend (去寫./Problems?ownerid=89827)

學校 : 不指定學校
編號 : 89827
來源 : [106.105.188.90]
最後登入時間 :
2024-05-15 21:49:25
d487. Order's computation process -- 學姊 | From: [106.105.188.90] | 發表日期 : 2019-03-31 20:01

#include <bits/stdc++.h>
using namespace std;

int main()
{
int n,a=1;

while(cin>>n){
if(n>0){
for(int i=n;i>0;i--){
a=a*i;

}
cout<<n<<"! =";
for(int j=n;j>0;j--){
cout<<" "<<j;
if(j==1) {
break;
}

cout<<" *";
}
cout<<" = "<<a<<endl;


}
else cout<<"0! = 1 = 1"<<endl;
}


return 0;

}

 
#17271: Re:這樣有錯媽


nevikw39 (牜攵)

學校 : 國立臺中第一高級中學
編號 : 89903
來源 : [140.114.207.96]
最後登入時間 :
2023-05-16 17:02:16
d487. Order's computation process -- 學姊 | From: [106.107.176.158] | 發表日期 : 2019-03-31 21:43

#include <bits/stdc++.h>
using namespace std;

int main()
{
int n,a=1;

while(cin>>n){
if(n>0){
for(int i=n;i>0;i--){
a=a*i;

}
cout<<n<<"! =";
for(int j=n;j>0;j--){
cout<<" "<<j;
if(j==1) {
break;
}

cout<<" *";
}
cout<<" = "<<a<<endl;


}
else cout<<"0! = 1 = 1"<<endl;
}


return 0;

}

你的 a 宣告在 while 迴圈外,所以記得每次迴圈開始前要重設為 1

話說 ZeroJudge 掛惹嗎

 
ZeroJudge Forum