HackerRank C- 1D Arrays in C
In this challenge, you have to create an array of size n dynamically, input the elements of the array, sum them and print the sum of the elements in a new line.
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
-
- int main() {
-
- int n,sum=0;
- scanf("%d",&n);
- int *a;
- a=(int*)malloc(n*sizeof(int));
-
- for(int i=0;i<n;i++)
- {
- scanf("%d",(a+i));
- sum=sum+*(a+i);
- }
- printf("%d",sum);
- return 0;
- }