Students Marks Sum

Sort by

recency

|

522 Discussions

|

  • + 0 comments

    Can someone please explain me this question ?

  • + 0 comments

    shortest way to do this is probably

    int marks_summation(int* marks, int number_of_students, char gender)
    {
        // Write your code here.
        int sum = 0;
        int i = (gender == 'g');
    
        while (i < number_of_students) {
            sum += marks[i];
            i += 2;
        }
        return sum;
    }
    
  • + 0 comments
    int marks_summation(int* marks, int number_of_students, char gender) {
       int sum=0;
       char g,b;
       for(int i=0;i<number_of_students;i++){
           if(i%2!=0 && gender=='g'){
               sum+=marks[i];
           }
           else if(i%2==0 && gender=='b'){
               sum+=marks[i];
           }
       }
       return sum;
    }
    
  • + 0 comments
    int sum=0;
      if(gender=='b'){
          for(int i=0;i<number_of_students;i+=2){
              sum+=marks[i];
          }
        return sum;
      }
      else{
          for(int i=1;i<number_of_students;i+=2){
              sum+=marks[i];    
          }
        return sum;
      }
    }
    
  • + 0 comments
    int sum = 0;
    
    for (int student = 0; student < number_of_students; student++) {
        if (gender == 'b') {
            sum += marks[student];
            student++;
        }
        else {
            student++;
            sum += marks[student];
        }
    }
    
    return sum;