You are given an array of integers, marks, and gender denoting the marks scored by students in a class.
The alternating elements marks0, marks2, marks4 and so on denote the marks of boys.Similarly, marks1, marks3, mark5 and so on denote the marks of girls.
Marks of boys if gender=b
Marks of girls if gender=g
Find the sum of marks based on gender given.
Input Format
The first line contains no of students in the class
The second line contains marks of the students.
Third line contains gender of the student
Answers
Answer:
I will try. to solve this complected question
Answer:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int marks_summation(int* marks, int number_of_students, char gender)
{
int sum = 0;
for (int i = (gender == 'b' ? 0 : 1); i < number_of_students; i = i + 2)
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 = 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);
return 0;
}
Explanation: