0% found this document useful (0 votes)
57 views

QUES - 6 - D4 - DS - Day - 4 Question - Contests - HackerRank

This document provides a coding challenge to write a C program to compute the sum of all elements in an array using pointers. The challenge tests the ability to iterate through an array using pointers and add each element to a running total (sum) variable. Sample input and output are provided showing an array of numbers and the expected output of the total sum.

Uploaded by

Arindam Ghosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

QUES - 6 - D4 - DS - Day - 4 Question - Contests - HackerRank

This document provides a coding challenge to write a C program to compute the sum of all elements in an array using pointers. The challenge tests the ability to iterate through an array using pointers and add each element to a running total (sum) variable. Sample input and output are provided showing an array of numbers and the expected output of the total sum.

Uploaded by

Arindam Ghosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

8/3/2021 QUES_6_D4 | DS_Day_4 Question | Contests | HackerRank

NEW
PRACTICE CERTIFICATION COMPETE JOBS LEADERBOARD  Search   arindam_ghosh007

All Contests

DS_Day_4

QUES_6_D4

QUES_6_D4

Problem Submissions Leaderboard Discussions

  
Write a program in C to compute the sum of all elements in an array using pointers.
Contest ends in
4 days
Input Format
Submissions:
3
NA
Max Score:
10
Constraints Difficulty: Medium

NA Rate This Challenge:







Output Format
More
NA

Sample Input 0

The number of elements to store in the array (max 10) : 5

5 number of elements in the array :

element - 1 : 2

element - 2 : 3

element - 3 : 4

element - 4 : 5

element - 5 : 6

Sample Output 0

The sum of array is: 20

Explanation 0

NA

Current Buffer
(saved locally, editable)
  

 C  

1 ▾#include<stdio.h>
2
3 ▾int sum(int *arr,int size){
4    int sum=0;
5    
6 ▾    for(int i=0;i<size;i++){
7        sum+=*(arr+i);
8   }
9    return sum;
10 }
11
12 ▾int main(){
13 ▾    int arr[]={2,3,4,5,6};
14 ▾    int size=sizeof(arr)/sizeof(arr[0]);
15    
16    printf("The sum of array is: %d",sum(arr,size));

https://www.hackerrank.com/contests/ds-day-4/challenges/ques-6-d4 1/2
8/3/2021 QUES_6_D4 | DS_Day_4 Question | Contests | HackerRank
17    return 0;
18 }

Line: 18
Col: 2

 Upload Code as File


Test against custom input Run Code
Submit Code

Testcase 0 ✓

Congratulations, you passed the sample test case.


Click the Submit Code button to run your code against all the test cases.

Input (stdin)

The number of elements to store in the array (max 10) : 5

5 number of elements in the array :

element - 1 : 2

element - 2 : 3

element - 3 : 4

element - 4 : 5

element - 5 : 6

Your Output (stdout)

The sum of array is: 20

Expected Output

The sum of array is: 20

Contest Calendar
|
Interview Prep
|
Blog
|
Scoring
|
Environment
|
FAQ
|
About Us
|
Support
|
Careers
|
Terms Of Service
|
Privacy Policy
|
Request a Feature

https://www.hackerrank.com/contests/ds-day-4/challenges/ques-6-d4 2/2

You might also like