PCDVD數位科技討論區

PCDVD數位科技討論區 (https://www.pcdvd.com.tw/index.php)
-   疑難雜症區 (https://www.pcdvd.com.tw/forumdisplay.php?f=34)
-   -   誰可以幫我寫出一個簡單的程式....QQ~! (https://www.pcdvd.com.tw/showthread.php?t=465775)

Sleepyhead 2005-03-31 07:07 PM

引用:
作者嚐起來像雞
Borland 非常肥大,啟動很慢.... :jolin:
寫命令列的我都用VC 6....
可是VC6有個大BUG....
for ( int i=0; i<2; i++ )
{
//...
}
int i=0; //VC顯示錯誤

很明顯地第一個i 是個區塊變數 (= = 可以這樣叫嗎),
生於for,死於for,
第二個i宣告時VC會跟你說變數重複宣告.... :p
很鳥!

我用MS Visual Studio 2003 裡的 VC.NET(7.0) 試過了,
已經不會出現error了,執行也正確,
但在default warning level 3下,還是會給個warning:
warning C4288: nonstandard extension used : 'i' : loop control variable declared in the for-loop is used outside the for-loop scope; it conflicts with the declaration in the outer scope

harrisonlin 2005-03-31 07:42 PM

參與一下漏斗型的討論:

代碼:
#include "iostream"

using namespace std;

void main() {
    for(int y = 0; y < 7; ++y) {
        for(int x = 0; x < 7; ++x) {
            if(y <= 3) {
                if((y == 0) || ((x >= y) && ((x + y) <= 6))) {
                    cout << "*";
                } else {
                    cout << " ";
                }
            } else {
                if((y == 0) || ((x <= y) && ((x + y) >= 6))) {
                    cout << "*";
                } else {
                    cout << " ";
                }
            }
        }
        cout << endl;
    }
}

Tirpitz 2005-03-31 09:18 PM

引用:
作者vanness70087
我可以把cout改成printf嗎~~???
因為COUT的指令還沒交~~~~!!
ENDL是結束的意思嗎~???


很多大大PO的程式碼已經不是純C的語法了吧?... :flash:

會害人...

你還是研究一下書吧

axbycz 2005-04-01 07:48 AM

引用:
作者Tirpitz
很多大大PO的程式碼已經不是純C的語法了吧?... :flash:

會害人...

你還是研究一下書吧

你是說這一個嗎? :ase:
#include <iostream>
using namespace std;
int main()
{
int y;
for(y=0; y<1; y++)
{
cout<<"*"<<endl;
cout<<"**"<<endl;
cout<<"***"<<endl;
cout<<"****"<<endl;
cout<<"*****"<<endl;
cout<<"****"<<endl;
cout<<"***"<<endl;
cout<<"**"<<endl;
cout<<"*"<<endl;
}
return 0;
}

axbycz 2005-04-01 08:03 AM

引用:
作者vanness70087
我可以把cout改成printf嗎~~???
因為COUT的指令還沒交~~~~!!
ENDL是結束的意思嗎~???

借一下 Wallace 兄的程式
#include <iostream>
using namespace std;
int main() {
int total=9;
for (int i=1;i<=total;i++) {
int curr_no=(i<=(total/2)) ? i:total-i+1;
for (int j=1;j<=curr_no;j++) {
printf("*");
}
printf("\n");
}
return 0;
}

axbycz 2005-04-01 08:09 AM

引用:
作者PAN_PAN
找台不要的電腦裝 Linux 或 FreeBSD
一裝好應該就有 g++ 可以用了 :)

謝謝你
我是忠實愛用者 :hungry:
Linux 的開發環境真的比 M$ 好很多

chou121 2005-04-01 09:10 AM

純 C 的程式

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

#define ROWCnt 9

void Case1()
{
int rowIdx;
int idx, starCnt;

printf("Case 1:\n");
for (rowIdx = 0; rowIdx < ROWCnt; rowIdx++)
{
starCnt = ((rowIdx < ROWCnt / 2) ? rowIdx + 1 : ROWCnt - rowIdx);
for (idx = 0; idx < starCnt; idx++)
printf("*");
printf("\n");
}
printf("\n");
}

void Case2()
{
int rowIdx;
int idx, spaceCnt, starCnt;

printf("Case 2:\n");
for (rowIdx = 0; rowIdx < ROWCnt; rowIdx++)
{
spaceCnt = ((rowIdx < ROWCnt / 2) ? rowIdx : ROWCnt - rowIdx - 1);
starCnt = ROWCnt - 2 * spaceCnt;
for (idx = 0; idx < spaceCnt; idx++)
printf(" ");
for (idx = 0; idx < starCnt; idx++)
printf("*");
printf("\n");
}
printf("\n");
}

int main()
{
Case1();
Case2();
return 0;
}

#ifdef __cplusplus
}
#endif

ahdeng 2005-04-01 09:16 AM

大家討論那麼多,不論是從compile environment或compile tools,
但最主要的是「誰可以幫我寫出一個簡單的程式....QQ~! 」
還是printf最簡單:jolin :jolin

vanness70087 2005-04-01 05:28 PM

我用你們寫的程式去學校跑~
沒有一個是對的= =
美一個錯誤都在5個以上~瘋掉~!

ahdeng 2005-04-01 06:13 PM

忘了提醒你,
寫程式不用很多時間,
因為大部份都花在debug!!


所有的時間均為GMT +8。 現在的時間是12:16 AM.

vBulletin Version 3.0.1
powered_by_vbulletin 2025。