HackerRank 1D arrays in c solution YASH PAL, 16 July 202416 July 2024 In this tutorial, we are going to solve HackerRank 1D Arrays in c problem solution with practical program code example and step-by-step explanation. in this problem, we need to take an integer input that will give the number of integer values we need to read from the next line and in the next line we have a number of integer values separated by space. after that, we need to print the sum of all the integers in the array. using this problem we are going to learn about the dynamic arrays in the c programming and how we can read the values dynamically and then iterate the array to calculate the sum of all the elements. there are the number of ways to solve this problem. 1D Array in c problem solution Solution in C programming #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.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); } 1D Array in C Second solution #include <stdio.h> int main() { int n,val,sum=0; scanf("%d",&n); while(n--) { scanf("%d",&val); sum+=val; } printf("%i",sum); } c coding problems hackerrank solutions cHackerRank