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));
[Link] 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
[Link] 2/2