有關C programming 陣列問題

2012-03-12 8:17 am
請問有無識C programming 嘅朋友仔可以解答我下面呢條題目呀:
就係有一個陣列(array)
係咁嘅{4, 3, 2.5, 4, -2, -4, 10, 8, -1, -3}代表著一間公司嘅利潤
呢家我要寫一條程式, 就係剩係計連續有利潤嘅時段, 但係去到有負數嘅就要停, 到有正數嘅又由頭開始計過, 最後將利潤最高時段嘅結果show出來,
即係話最後結果會係18.0
我試過好多次都係可以跳過啲負數, 但係唔可以將負數隔開嘅正數時段分開來計, 請問有無好心嘅高手們可以幫一幫忙呀?

回答 (2)

2012-03-12 7:24 pm
✔ 最佳答案

圖片參考:http://imgcld.yimg.com/8/n/HA04801976/o/701203120001813873448250.jpg


This should work.


2012-03-12 11:28:24 補充:
variable int num is the number of elements in the array. If you change the array, change this variable to reflect the correct number of elements in your array.

2012-03-13 08:51:52 補充:
Yes, there is a * before index. index is a pointer. It will be needed in the sum subroutine and the value of (*index) will be changed if needed.

2012-03-13 13:00:19 補充:
1. simply change all the double declaration to float.
2. instead of using index as a parameter to the function, use a global variable
3. shoot me an e-mail if there is any more information given/needed
2012-03-13 8:41 am
唔好意思, 睇得唔係太清楚, 請問index係唔係前面有個*, 即係pointer符號呀. 唔該:)

2012-03-13 12:27:58 補充:
my function is given as float sum(float array[], int number)


收錄日期: 2021-04-30 12:58:53
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20120312000051KK00018

檢視 Wayback Machine 備份