-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.c
More file actions
58 lines (43 loc) · 912 Bytes
/
test.c
File metadata and controls
58 lines (43 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <malloc.h>
#define LEN 50
#define LEN_STATIC 80
#define LEN_RESULT 100
int func(int n);
int main(void){
int j;
int *array;
int array_static[LEN_STATIC] = {0};
long result;
j = 0;
array = NULL;
array = (int*)malloc(LEN * sizeof(int));
result = 0;
for (j = 1; j < LEN_RESULT; ++j){
result += j;
}
if (array != NULL){
for (j = 0; j < LEN; ++j){
array[j] = j * 2;
}
}
else {
printf("array is a NULL pointer.\n");
return 1;
}
for (j = 0; j < LEN_STATIC; ++j){
array_static[j] = j * 3;
}
printf("result[1-100] = %ld \n", result);
printf("result[1-250] = %d \n", func(250));
free(array);
return 0;
}
int func(int n){
int sum, i;
sum = 0;
for(i = 0; i < n; ++i){
sum += i;
}
return sum;
}