- 445 名前:デフォルトの名無しさん mailto:sage [2007/07/04(水) 21:01:14 ]
- こんな感じ
#include <stdio.h> #include <stdlib.h> void fill(int *begin, int *end, int first, int step) { int *p; int n = first; for(p = begin; p != end; p++, n += step) { *p = n; } } int sum(int *begin, int *end) { int *p; int n = 0; for(p = begin; p != end; p++) { n += *p; } return n; } #define SIZE 5 int main() { int *p = malloc(sizeof (int) * SIZE); if(p == NULL) { return EXIT_FAILURE; } fill(p, p + SIZE, 0, 1); printf("%d\n", sum(p, p + SIZE)); free(p); }
|

|