# 1D Arrays in C Hacker Rank Solution

Hello coders, In this post, you will learn how to solve the 1D Arrays in C Hacker Rank Solution. This problem is a part of the HackerRank C Programming Series.

We also provide Hackerrank solutions in C++Java programming, and Python Programming languages so whatever your domain we will give you an answer in your field.

You can practice and submit all HackerRank problem solutions in one place. Find a solution for other domains and Sub-domain. I.e. Hacker Rank solution for HackerRank C ProgrammingHackerRank C++ ProgrammingHackerRank Java Programming, HackerRank Python ProgrammingHackerRank Linux ShellHackerRank SQL Programming, and HackerRank 10 days of Javascript.

As you already know that this site does not contain only the Hacker Rank solutions here, you can also find the solution for other problems. I.e. Web Technology,Data StructuresRDBMS ProgramsJava Programs Solutions,  Fiverr Skills Test answersGoogle Course AnswersLinkedin Assessment, and Coursera Quiz Answers.

## 1D Arrays in C Hacker Rank Solution

### Objective

An array is a container object that holds a fixed number of values of a single type. To create an array in C, we can do `int arr[n];`. Here, arr, is a variable array which holds up to 10 integers. The above array is a static array that has memory allocated at compile time. A dynamic array can be created in C, using the malloc function and the memory is allocated on the heap at runtime. To create an integer array, arr of size n`int *arr = (int*)malloc(n * sizeof(int))`, where arr points to the base address of the array.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.

#### Input Format

The first line contains an integer,n.The next line contains n space-separated integers.

• 1<=n<=1000
• 1<=a<=1000

#### Output Format

Print in a single line the sum of the integers in the array.

```6
16 13 7 2 1 12
```

```51
```

#### Sample Input 1

```7
1 13 15 20 12 13 2
```

`76`

### 1D Arrays in C – Hacker Rank Solution

```#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, *arr, i, sum = 0;
scanf("%d", &n);
arr = (int*) malloc(n * sizeof(int));
for(i = 0; i < n; i++) {
scanf("%d", arr + i);
}
for(i = 0; i < n; i++) {
sum += *(arr + i);
}
printf("%d\n", sum);
free(arr);
return 0;
}```

Disclaimer: The above Problem (1D Arrays in C ) is generated by Hackerrank but the Solution is Provided by Chase2Learn. This tutorial is only for Educational and Learning purposes. Authority if any of the queries regarding this post or website fill the following contact form thank you.

### FAQ:

#### Is HackerRank good for C?

HackerRankHackerRank offers you to solve these programming challenges in any of various programming languages such as C, Java, Python, Ruby, etc. Apart from this, participants can solve the problems in various computer science domains like algorithms, machine learning, and artificial intelligence.

#### What is meant by HackerRank?

HackerRank is a tech company that focuses on competitive programming challenges for both consumers and businesses. Developers compete by writing programs according to provided specifications. Wikipedia

#### Is HackerRank good for beginners?

HackerRank is very good for beginners so even if you want to print your first program “Hello World!” then definitely HackerRank gives this opportunity to you. It has a pretty good UI with boilerplate code pre-written that helps beginners to start competitive coding.

#### What is C programming in simple words?

C is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C’s features cleanly reflect the capabilities of the targeted CPUs. Wikipedia

#### Where can I find HackerRank solutions in C?

in this post you will get all the solutions of HackerRank C Problems.

Finally, we are now, in the end, I just want to conclude some important message for you

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Please share our posts on social media platforms and also suggest to your friends to Join Our Groups. Don’t forget to subscribe.

Sharing Is Caring