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){//Write your code here.inttotal=0;if(gender=='g'){for(inti=0;i<number_of_students;i++){if(i%2==1)total+=marks[i];}}elseif(gender=='b'){for(inti=0;i<number_of_students;i++){if(i%2==0)total+=marks[i];}}returntotal;}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 →