- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C program to find marks of students for boys or girls

Suppose we have an array called marks, where some marks are given, all even indices marks like marks[0], marks[2] and so on are holding marks of boys and all even indexed marks are holding for girls. We have another input called gender. The value of gender is either 'b' or 'g', when it is 'b' we shall have to return the sum of all boys, and when it is 'g' return sum of marks for all girls. (Size of array is N)

So, if the input is like N = 9 marks = [8,5,2,6,7,5,9,9,7] gender = 'g', then the output will be 25 because 5 + 6 + 5 + 9 = 25.

To solve this, we will follow these steps −

- g_sum := 0
- b_sum := 0
- for initialize i := 0, when i < n, update (increase i by 1), do:
- if i mod 2 is 1, then:
- g_sum := g_sum + marks[i]

- Otherwise
- b_sum := b_sum + marks[i]

- if i mod 2 is 1, then:
- if gender is same as 'b', then:
- return b_sum

- return g_sum

## Example

Let us see the following implementation to get better understanding −

#include <stdio.h> #define N 9 int solve(int marks[], int n, char gender){ int g_sum = 0; int b_sum = 0; for(int i = 0; i < n; i++){ if(i % 2 != 0){ g_sum += marks[i]; }else{ b_sum += marks[i]; } } if(gender == 'b') return b_sum; return g_sum; } int main(){ int marks[N] = {8,5,2,6,7,5,9,9,7}; char gender = 'g'; int sum = solve(marks, N, gender); printf("%d", sum); }

## Input

{8,5,2,6,7,5,9,9,7}, 'g'

## Output

25

- Related Questions & Answers
- What generally boys like in girls?
- What type of boys girls are usually attract to?
- Finding average marks of students for different subjects and display only the highest average marks in MySQL
- Maximum students to pass after giving bonus to everybody and not exceeding 100 marks in C++ Program
- C++ code to find position of students after coding contest
- Maximum students to pass after giving bonus to everybody and not exceeding 100 marks in C++
- Python program to find average score of each students from dictionary of scores
- Effective Ways of Preparing Notes for Students
- C++ program to find maximum distance between two rival students after x swaps
- What are the common physical changes, problems in boys and girls during Adolescent and what parents can do?
- Exam guidelines for engineering students
- Different possible marks for n questions and negative marking in C++ Program
- How can students make most out of the classes they find boring or difficult?
- C# program to find Union of two or more Dictionaries
- C# program to find Union of two or more Lists

Advertisements