Explanation 0<\/strong><\/p>\n\n\n\nmarks = [3, 2, 5] and gender = b.<\/p>\n\n\n\n
So, marks0 + marks2 = 3 + 5 = 8.<\/p>\n\n\n\n
Sample Input 1<\/strong><\/p>\n\n\n\n5\n1\n2\n3\n4\n5\ng\n<\/code><\/pre>\n\n\n\nSample Output 1<\/strong><\/p>\n\n\n\n6\n<\/code><\/pre>\n\n\n\nExplanation 1<\/strong><\/p>\n\n\n\nmarks = [1, 2, 3, 4, 5] and gender = g <\/p>\n\n\n\n
So, sum = marks1 + marks3 = 2 + 4 = 6.<\/p>\n\n\n\n
Sample Input 2<\/strong><\/p>\n\n\n\n1\n5\ng\n<\/code><\/pre>\n\n\n\nSample Output 2<\/strong><\/p>\n\n\n\n0<\/code><\/pre>\n\n\n\nExplanation 2<\/strong><\/p>\n\n\n\nmarks = [5] and gender = g \nHere, marks1 does not exist. So, sum = 0.\n<\/code><\/pre>\n\n\n\n<\/span>Solution – Students Marks Sum HackerRank Solution in C<\/strong><\/span><\/h2>\n\n\n\n#include <stdio.h>\n#include <string.h>\n#include <math.h>\n#include <stdlib.h>\n\n\/\/Complete the following function.\n\nint marks_summation(int* marks, int number_of_students, char gender) {\n \/\/Write your code here.\n int sum = 0,i=0;\n for( i=(gender=='g'?1:0);i<number_of_students;i=i+2)\n {\n sum += *(marks+i);\n }\n \n return sum;\n}\n\nint main() {\n int number_of_students;\n char gender;\n int sum;\n \n scanf(\"%d\", &number_of_students);\n int *marks = (int *) malloc(number_of_students * sizeof (int));\n \n for (int student = 0; student < number_of_students; student++) {\n scanf(\"%d\", (marks + student));\n }\n \n scanf(\" %c\", &gender);\n sum = marks_summation(marks, number_of_students, gender);\n printf(\"%d\", sum);\n free(marks);\n \n return 0;\n}\n<\/pre>\n\n\n\n