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

以下程式執行時,我輸入,數字1完ENTER
數字2完ENTER然後一直 打到10 ENTER
,然後會自動跑出0 到 10 ,,多了0的數字跑出來..?

不知可否改成,,自動跑出1 到 10就好,
0的數字不要讓他跑出來?
當然也是..程式啟動執行後,我輸入,數字1完ENTER
,數字2完ENTER然後一直 打到10 ENTER..後
才自動跑出1 到 10就好,謝謝

#include
#include

struct Node
{
int data;
struct Node * pNext;
};
int main()
{
Node * pStart, * pCurrent, * pTmp;
pStart = pCurrent = pTmp = NULL;
pCurrent = new Node;
pStart = pCurrent;
for (int i=1; i<11; i++)
{
pTmp = new Node;
cin >> pTmp->data;
pTmp ->pNext =NULL;
pCurrent->pNext = pTmp;
pCurrent=pCurrent ->pNext ;
}
for( pCurrent=pStart; pCurrent!=NULL;
pCurrent=pCurrent->pNext )
cout << pCurrent->data << endl;
system("PAUSE");
return 0;
}

2007-01-18 12:55:09 · 2 個解答 · 發問者 開心果 2 in 電腦與網際網路 程式設計

2 個解答

Node * pStart, * pCurrent, * pTmp;
pStart = pCurrent = pTmp = NULL;
pCurrent = new Node;
cin >> pCurrent->data; /* 這裡已經有一個 Node 了 需要放 地一個值 */
pStart = pCurrent;
for (int i=2; i<11; i++) /* 已經放了一個, 從第二個開始 */
{
pTmp = new Node;
cin >> pTmp->data;
pTmp ->pNext =NULL;
pCurrent->pNext = pTmp;
pCurrent=pCurrent ->pNext ;
}
for( pCurrent=pStart; pCurrent!=NULL;
pCurrent=pCurrent->pNext )
cout << pCurrent->data << endl;
system("PAUSE");
return 0;
}
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.

2007-01-19 00:16:56 · answer #1 · answered by JJ 7 · 0 0

#include
int main()
{
int i;
for(i=1;i<=10;i++)
cout< system("pause");
return 0;
}

2007-01-22 05:53:53 · answer #2 · answered by 銘彥 1 · 0 0

fedest.com, questions and answers