English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

題目:1*3*5*....*n
螢幕會顯示:please key in 'n' value:(例如輸入5)
1*3*5=15
please key in 'n' value:(例如輸入7)
1*3*5*7=105
要怎嚜寫~我想了很久
適用for迴圈下去做的

2007-10-20 09:45:50 · 3 個解答 · 發問者 ting 1 in 電腦與網際網路 程式設計

3 個解答

鴨子的程式有bug, 如果N是偶數的話, 應該要顯示錯誤訊息.

#include
using namespace std;
int main()
{
int n;
int sum=1;
cout<<"Please Key in 'N' value:";
cin>>n;
while(n%2==0)
{
cout<<"N should be an odd integer, input again:";
cin>>n;
}

for(int i=1;i<=n;i=i+2)
{
if(i!=n)
cout< else
cout< product=product*i;
}
cout<
return 0;
}

2007-10-20 11:10:04 · answer #1 · answered by ? 6 · 0 0

#include
#include
int main(int argc, char* argv[]){
//=====START=====//
int n,i,sum=0;
printf("Please key in \'n\' value:"),scanf("%d",&n);
if(n&1){
for(i=0;i<=(n-1)/2;i++){
sum+=(2*i+1),printf("%d*",(2*i+1));
}
printf("\b=%d\n",sum);
}else{
printf("%d is Even.\n",n);
}
//=====END=====//
system("PAUSE");
return 0;
}

2007-10-20 16:53:59 · answer #2 · answered by Big_John-tw 7 · 0 0

#include
using namespace std;
int main()
{

int n;
int sum=1;
cout<<"Please Key in 'N' value:";
cin>>n;
for(int i=1;i<=n;i=i+2)
{
if(i!=n)
cout< else
cout< sum=sum*i;
}
cout<
return 0;
}

2007-10-20 10:16:22 · answer #3 · answered by 鴨子 2 · 0 0

fedest.com, questions and answers