You are viewing a single comment's thread. Return to all comments →
Mostly agreed, it's a poorly written challenge. They want:
#include <stdio.h> int main() { int n,sum=0; scanf("%d",&n); int *val = malloc(n*sizeof(int)); for(int i=0;i<n;i++) { scanf("%d",&val[i]); sum+=val[i]; } printf("%i",sum); free(val); }
But there's no reason to store the values. There would be, if you were required to sum all values, then reprint each value. Otherwise you can just..
#include <stdio.h> int main() { int n,val,sum=0; scanf("%d",&n); while(n--) { scanf("%d",&val); sum+=val; } printf("%i",sum); }
Seems like cookies are disabled on this browser, please enable them to open this website
1D Arrays in C
You are viewing a single comment's thread. Return to all comments →
Mostly agreed, it's a poorly written challenge. They want:
But there's no reason to store the values. There would be, if you were required to sum all values, then reprint each value. Otherwise you can just..