Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerRank 1D arrays in c solution

YASH PAL, 16 July 202416 June 2025

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.

1D Array in C

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

coding problems solutions HackerRank C 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 *

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

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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