[問題] Devc++輸出問題

看板C_and_CPP (C/C++)作者 (gary)時間15年前 (2011/03/21 11:03), 編輯推噓1(109)
留言10則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Dec-c++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): sum1輸出的值有問題 如果我要把輸出的數值變成一個OUTPUT檔, 則該怎麼編輯? 餵入的資料(Input): 輸入值=30.4108 預期的正確結果(Expected Output): when the i=1, follow, x=1, sum1=1.91e-16 when the i=1, follow, x=2, sum1=1.51e-7 when the i=1, follow, x=3, sum1=9.86e-5 錯誤結果(Wrong Output): when the i=1, follow, x=1, sum1=1.#INF00E+000 程式碼(Code):(請善用置底文網頁, 記得排版) #include <stdio.h> #include <stdlib.h> #include <math.h> int main(int argc, char *argv[]) { int i; float a; float b; double x, sum; double y, sum1; double z, sum2; printf("argc= %d \n", argc); for (i=0;i<argc;i++) { printf("i= %d, argv= [%s]\n", i, argv[i]); } system("pause"); // ---------------------------------------------------- sum=0.0; sum1=0.0; sum2=0.0; for (i=1;i<argc;i++) { for (x=1;x<=5;x++){ a= 3.00e+10; b= 6.626e-34; sum= a*b*atof(argv[i])/x; y= exp(sum); z= exp(-sum); sum1=y*pow((sum/(z-1)),2); printf("when the, i= %d, follow, x= %.6lf, sum1= %.6lf\n", i, x, sum1); } } system("pause"); return 0; } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.122.142.99 ※ 編輯: garyer 來自: 140.122.142.99 (03/21 11:14)

03/21 11:23, , 1F
變成output檔:你需要fopen, fprintf, fclose這些函式
03/21 11:23, 1F

03/21 11:23, , 2F
(或者也可以直接用命令重導向啦...XD)
03/21 11:23, 2F

03/21 11:27, , 3F
書上有寫,但小弟還沒學到......目前努力中
03/21 11:27, 3F

03/21 11:28, , 4F
不過可以請大大教一下麼@@"
03/21 11:28, 4F

03/21 11:29, , 5F
書上或網路上一定會有清楚的範例的 XD
03/21 11:29, 5F

03/21 11:32, , 6F
03/21 11:32, 6F

03/21 11:33, , 7F
sum是6.045059e-22 這麼小的值 exp()算的出來嗎?
03/21 11:33, 7F

03/21 11:33, , 8F
我這邊的exp()回了個 1.0e+00 給我 @@
03/21 11:33, 8F

03/21 11:34, , 9F
確定在EXCEL上是算得出來的..但是換到這邊卻顯現不出來
03/21 11:34, 9F

03/21 13:41, , 10F
還有freopen()喔~
03/21 13:41, 10F
文章代碼(AID): #1DXi0Up4 (C_and_CPP)
文章代碼(AID): #1DXi0Up4 (C_and_CPP)