Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(){
- /*************** practice ******************/
- // declare variables
- int n;
- int* scores; // 將此指標當作array來用
- // good habit - remove the remaining '\n' after using scanf
- scanf("%d",&n);
- char tmp_ch[1];
- gets(tmp_ch);
- // get memory
- size_t scores_size = sizeof(int)*n;
- scores = (int*)malloc(scores_size);
- // get input and sum
- int i, sum = 0;
- for (i = 0; i < n; i++){
- // scanf("%d",&scores[i]); // kind of redundant
- scanf("%d",scores+i); // better
- sum += *(scores+i);
- }
- // show result
- printf("sum: %d\n", sum);
- return 0; // 0 - normal exit
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement