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.intsum=0;for(inti=(gender=='b'?0:gender=='g'?1:-1);i<number_of_students;i+=2){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 →