Math Pro 數學補給站's Archiver

不是井裡沒有水,而是我們挖的不夠深;
不是成功來的慢,而是我們放棄的太快。

ksjeng 發表於 2010-10-24 23:27

如何使system("Pause")最後再執行?

向老師請益
我看到一些網頁中
有不錯的程式碼
想抓下來用DEV C++(4.9.9.2)([url=http://www.math.ncu.edu.tw/~jovice/c++/boards/devcpp.htm]http://www.math.ncu.edu.tw/~jovice/c++/boards/devcpp.htm[/url])測試一遍
但遇到幾個問題
1.程式碼複製貼上後,按執行卻出現錯誤,請問我該如何解決?
譬如在這個網頁([url=http://programming.im.ncnu.edu.tw/C_index.html]http://programming.im.ncnu.edu.tw/C_index.html[/url])抓下來的:

執行後如底下張圖片:
[img]https://math.pro/db/[url=http://www.flickr.com/photos/29777028@N02/5110932942/][img=755,413]http://farm2.static.flickr.com/1088/5110932942_b90c8cb305.jpg[/img][/url][/img]


2.但執行後立即消失,我想把system("Pause")加進去,但卻失敗,我該如何處置?
[img]https://math.pro/db/%3Ca%20href=[/img][img=697,402]http://farm2.static.flickr.com/1407/5110415053_94deef5c85.jpg[/img]" border="0">

[[i] 本帖最後由 ksjeng 於 2010-10-24 11:53 PM 編輯 [/i]]

weiye 發表於 2010-10-25 08:58

建議試試看:

1. 在引入標頭檔的地方加入一行 #include <stdlib.h>

2. 將 system("PAUSE"); 這行放在 main 函式的倒數第二行,也就是 return 之前。

ksjeng 發表於 2010-10-25 18:58

謝謝老師
程式碼如下
/* pow example */
#include <stdio.h>
#include <math.h>

int main ()
{
  printf ("7 ^ 3 = %lf\n", pow (7,3));
  printf ("4.73 ^ 12 = %lf\n", pow (4.73,12));
  printf ("32.01 ^ 1.54 = %lf\n", pow (32.01,1.54));
  return 0;
}

我該放在哪裡才能讓它慢慢執行啊

weiye 發表於 2010-10-25 19:13

放在 return 的前一行,

因為 return 之後,主函式就結束了。

ksjeng 發表於 2010-10-25 20:07

出現了錯誤,懇請撥冗協助

[img]https://math.pro/db/%3Ca%20href=[/img][img=684,471]http://farm2.static.flickr.com/1373/5114232812_a358a44c11.jpg[/img]" border="0">

[[i] 本帖最後由 ksjeng 於 2010-10-25 08:38 PM 編輯 [/i]]

weiye 發表於 2010-10-25 20:39

那我就不知道啦。 :-)

ksjeng 發表於 2010-10-28 21:41

再加上 #include <stdlib.h>
就成功了
謝謝老師

頁: [1]

論壇程式使用 Discuz! Archiver   © 2001-2022 Comsenz Inc.