Skip to content

Instantly share code, notes, and snippets.

@boxp
Last active December 18, 2015 11:59
Show Gist options
  • Save boxp/5779579 to your computer and use it in GitHub Desktop.
Save boxp/5779579 to your computer and use it in GitHub Desktop.
プログラム基礎Ⅱの小テストを変数無しで解いてみる試みその1
#include <stdio.h>
int sum(const int num[],const int count,const int result){
if (count == 0) {
return result + num[count];
} else {
sum(num,(count-1),(result + num[count]));
}
}
int main(void)
{
const int num[10] = {10,9,8,7,6,5,4,3,2,1};
printf("sum = %d\n", sum(num,9,0));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment