我需要一個遞歸函數在Ç,支票/在奇數位置中的陣列的偶數位置比較值(整數)的總和,與值的總和。還打印(功能內)較大的和!C程序遞歸函數奇數
像:
printf("\nThe bigger sum is %d. \n evensum = %d , oddsum = %d \n",bigger, evensum, oddsum);
假設數組有8個位置,我們填補它的main()用隨機值。
這是我到目前爲止有:
#include <stdio.h>
#define N 4
int checksum(int matrix[], int position, int sum1, int sum2);
int main(void)
{
int mat[N];
int i,j;
printf("\nEnter the %d numbers:\n", N);
for(i = 0; i < N; i++)
{
printf("%2d> ",i);
scanf("%d", &mat[i]);
}
checksum(mat, 0, 0, 0);
}
int checksum(int m[], int pos, int s1, int s2){
if(pos<N){
if(pos==0){
s1 = m[pos];
checksum(m, pos+1, s1, s2);
}else{
if(pos%2){
return s1 + checksum(m, pos+1, s1, s2);
}else{
return s2 + checksum(m, pos+1, s1, s2);
}
}
}
}
您應該嘗試自己編寫該程序。如果您遇到具體問題,請發佈您的代碼並尋求指導。 – MacGucky 2011-03-24 01:14:34
我試過這個:http://pastie.org/1706480 – Lamp 2011-03-24 01:22:07
你要求stackoverflow做你的功課?哇。哇哇! -1。 – 2011-03-24 01:28:46