C Program to print the sum of marks of Boys and Girls stored in an Array at alternate positions - HackerRank

 


// Program by Akash Tripathi (@proakash256) 
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

//Complete the following function.

int marks_summation(int *marksint number_of_studentschar gender)
{
    //Write your code here.
    int sum = 0;
    if(gender == 'b')
    {
        for(int i = 0i <= number_of_studentsi = i + 2)
            sum = sum + marks[i];
        return sum;
    }
    else if(gender == 'g')
    {
        for(int i = 1i <= number_of_studentsi = i + 2)
            sum = sum + marks[i];
        return sum;
    }
}

int main()
{
    int number_of_students;
    char gender;
    int sum;
    scanf("%d", &number_of_students);
    int *marks = (int *)malloc(number_of_students * sizeof(int));
    for (int student = 0student < number_of_studentsstudent++)
    {
        scanf("%d", (marks + student));
    }
    scanf(" %c", &gender);
    sum = marks_summation(marksnumber_of_studentsgender);
    printf("%d"sum);
    free(marks);
    return 0;
}

Comments