-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentMarksSum.c
More file actions
45 lines (35 loc) · 1018 Bytes
/
StudentMarksSum.c
File metadata and controls
45 lines (35 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Question link - https://www.hackerrank.com/challenges/students-marks-sum/problem?isFullScreen=true
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//Complete the following function.
int marks_summation(int* marks, int number_of_students, char gender) {
//Write your code here.---
int sum = 0;
if(gender == 'b'){
for (int i = 0; i < number_of_students ; i+=2){
sum += marks[i];
}
}else {
for (int i = 1; i < number_of_students; i += 2) {
sum += marks[i];
}
}
return sum;
}
int main() {
int number_of_students;
char gender;
int sum;
scanf("%d", &number_of_students);
int *marks = (int *) malloc(number_of_students * sizeof (int));
for (int student = 0; student < number_of_students; student++) {
scanf("%d", (marks + student));
}
scanf(" %c", &gender);
sum = marks_summation(marks, number_of_students, gender);
printf("%d", sum);
free(marks);
return 0;
}