Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • 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
HackerRank 1D Arrays in C problem solution

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

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 *

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes