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

寫一程式讀入兩個整數a與b,如果ab則印出a, a-1, a-2, …, b;如果a, b相等且為正數則印出a個Hello;如果a, b相等且為負數則印出 -a個Bye;如果a, b皆為零則不印出任何東西。輸出時每次一行。

2007-12-23 09:55:50 · 3 個解答 · 發問者 ㄚ布 2 in 電腦與網際網路 程式設計

3 個解答

#include
using namespace std;

int main() {
int a,b;
cout << "請輸入兩個整數:";
scanf("%d%d",&a,&b);
if(a cout << "a,";
for(int i=1;i<=b;i++) cout << "a+" << i << ",";
}
if(a>b) {
cout << "a,";
for(int i=1;i<=a;i++) cout << "a-" << i << ",";
}

if(a==b && a>0) for(int i=0;i if(a==b && a<0) for(int i=a;i<0;i++) cout << "bye ";
if(a==0 && b==0);

cout << endl;
return 0;
}


2007-12-23 12:49:39 · answer #1 · answered by u9323523 5 · 0 0

//Power by Visual Studio 2005
//Download Site: http://www.microsoft.com/taiwan/vstudio/express/
#include
#include
using namespace std;
int main(int argc, char** argv){
//=====START=====//
int a,b;
char buffer[32767];
cout<<"Input a: ",cin>>a,cout<<"Input b: ",cin>>b;
for(int i=(a!=b?a:0);i!=(a!=b?(b+(a>b?-1:1)):abs(a));i+=(a>b?-1:1))
{
cout<<(a!=b?itoa(i,buffer,10):(a!=0?(a<0?"Bye":"Hello"):""))< }
//=====END=====//
system("PAUSE");
return 0;
}

2007-12-23 18:05:53 補充:
僅僅單靠一個迴圈加運算子來完成五個工作~~

2007-12-23 13:04:41 · answer #2 · answered by Big_John-tw 7 · 0 0

Please do it by yourself. It's a simple problem.

2007-12-23 11:31:22 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers