[問題] 如何自訂個函數改變2維結構的值?

看板C_and_CPP (C/C++)作者 (電風)時間13年前 (2012/09/26 03:29), 編輯推噓0(004)
留言4則, 4人參與, 最新討論串1/1
開發平台: 用codeblock 寫的c++ 程式碼: #include <stdio.h> #define MAX_TERMS 101 /* max # of terms */ #define MAX_POLYS 15 /* max # of polynomials */ /* represents a term in polynomial */ typedef struct { float coef; int expon; } polynomial; /* data pool, we store all polynomials here */ polynomial terms[MAX_POLYS][MAX_TERMS]; /*********** 以下是我寫的 *******************/ void Zero (polynomial a[])){ for(int i=0; i<MAX_TERMS; i++){ a[][i].coef=0; a[][i].expon=0; } } 說明和問題: polynomial terms [MAX_POLYS][MAX_TERMS] 可以存15個多項式各101項的係數跟指數 我要寫個函數 Zero(terms[n]) 傳入的東西一定要是terms[n] ,n可以自己設 讓terms[n][全部].coef=0 terms[n][全部].expon=0 只是照我上面那樣的寫法 沒辦法改變terms 我不太懂要怎樣參數只有terms[n] 卻可以改變terms[n][i] -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.25.224.53

09/26 04:51, , 1F
雙層迴圈不就搞定了嗎
09/26 04:51, 1F

09/26 08:13, , 2F
可是n是指定的耶
09/26 08:13, 2F

09/26 15:05, , 3F
看不太懂 orz 不過我猜改成 a[i].coef=0; 應該就可以了..
09/26 15:05, 3F
可以了~

09/26 20:33, , 4F
這 code 明明是 c 不是 c++ ... = =
09/26 20:33, 4F
※ 編輯: mumuge18 來自: 220.137.168.72 (09/27 18:11)
文章代碼(AID): #1GOWO9K- (C_and_CPP)
文章代碼(AID): #1GOWO9K- (C_and_CPP)