We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>//Complete the following function.intmarks_summation(int*marks,intnumber_of_students,chargender){intsum=0;for(inti=0;number_of_students-1>=i;i++){if((i%2==0&&gender=='b')||(i%2!=0&&gender=='g'))sum+=marks[i];}returnsum;}intmain(){intnumber_of_students;chargender;intsum;scanf("%d",&number_of_students);int*marks=(int*)malloc(number_of_students*sizeof(int));for(intstudent=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);return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Students Marks Sum
You are viewing a single comment's thread. Return to all comments →