Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone
HackerRank 1D Arrays in C problem solution

HackerRank 1D arrays in C solution

YASH PAL, 16 July 202416 January 2026

HackerRank 1D Arrays in C solution – In this tutorial, we are going to solve HackerRank 1D Arrays in c 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.

HackerRank 1D Arrays in C problem solution
HackerRank 1D Arrays in C problem solution

1D arrays in C Solution.

#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);
}

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);
}

Next problem solution – HackerRank Array Reversal in C solution

C Solutions coding problems solutions Hackerrank Problems Solutions cHackerRank

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Hello world in c solution
Playing with characters problem solution
sum and difference of two numbers problem solution
functions in c problem solution
pointers in c problem solution
Conditional statements in c problem solution
For loop in c solution
Sum of Digits of a five-digit number problem solution
Bitwise operators problem solution
Printing pattern using loops problem solution
1D Arrays in c problem solution
Array Reversal problem solution
Printing Tokens problem solution
Digit Frequency problem solution
Dynamic Array in c problem solution
Calculate the Nth term problem solution
Students Marks sum problem solution
Sorting Array of strings problem solution
Permutations of strings problem solution
Variadic functions in c problem solution
Querying the documents problem solution
Boxes through a tunnel problem solution
Small Triangles, Large Triangles problem solution
post-transition problem solution
Structuring the document problem solution

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes