QUES - 6 - D4 - DS - Day - 4 Question - Contests - HackerRank
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
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
Sample Input 0
element - 1 : 2
element - 2 : 3
element - 3 : 4
element - 4 : 5
element - 5 : 6
Sample Output 0
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
Testcase 0 ✓
Input (stdin)
element - 1 : 2
element - 2 : 3
element - 3 : 4
element - 4 : 5
element - 5 : 6
Expected Output
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