Re: 參考書本範例,卻錯誤一堆的C語言範例..

看板Programming作者 (我愛ASM)時間18年前 (2007/07/19 02:39), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《quota@kkcity.com.tw (忘了改暱稱.:P)》之銘言: : 我的程式碼如下 : 麻煩各位幫忙了 : 謝謝! 你用的書應該有點年紀了^_^。code稍稍修改一下。 #include <stdio.h> #include <stdlib.h> //應該用不到dos.h了 #define SIZE 100 int functiona(int a[], int size); //你原來的functiona有做累加的動作,我不確定裡面的total變數功能 //不過我把他先傳出來所以回傳值是int int main(int argc, char *argv[]) { int a[SIZE]; int i; int result; for(i = 0; i <100; i++){a[i] = 1;} //因為for迴圈都把i和a[]初始化了,所以變數直接宣告就好。 for(i = 0; i <100; i++){printf("%d",a[i]);} result = functiona(a , SIZE); //小小變動 printf("\n%d",result); //也是小小變動 system("PAUSE"); return 0; } int functiona(int a[], int size) { int i,total = 0; for(i = 0; i < size; i++) total += a[i]; return total; } //原來裡面的system()應該是你要檢查用的吧?先拿掉了.... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.132.23.74
文章代碼(AID): #16dbv77U (Programming)
文章代碼(AID): #16dbv77U (Programming)