- 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

# Maximum students to pass after giving bonus to everybody and not exceeding 100 marks in C++ Program

In this problem, we are given an array stu[] of size n denoting the marks of students in the class. For each student, the maximum mark is 100 and a student needs 50 marks to pass the exam. Our task is to create a program to find the Maximum students to pass after giving a bonus to everybody and not exceeding 100 marks.

**Problem Description** − We need to give bonus marks to students to pass but the bonus marks will be given to all students. Our task is to maximize the number of students that can pass the exam by giving the bonus marks but no student should get marks more than 100 after giving a bonus. And then return the maximum number of students passing.

**Let’s take an example to understand the problem,**

## Input

stu[] = {45, 32, 78, 10, 53, 67}

## Output

5

## Explanation

All students passed are : 45 + 22 = 67 32 + 22 = 54 78 + 22 = 100 53 + 22 = 75 67 + 22 = 89

## Solution Approach

To solve the problem, we need to give marks to the student but one thing to consider is the maximum marks of any student should not exceed 100. So the maximum bonus that can be given is

Student with max marks(M) + bonus = 100 Bonus = 100 − M

Then we will add this bonus to students' current marks. If it exceeds 50, students pass. The result will be the count of all such students.

## Algorithm

**Initialise**

passCount = 0;

**Step 1** −

Find the student with maximum marks, maxMarks.

**Step 2** −

Calculate bonus that can be given to all students, bonus = 100 − maxMarks.

**Step 3** −

Loop for i −> 0 to n−1

**Step 3.1** −

if(stu[i] + bonus >= 50), passCount++.

**Step 4** −

return passCount.

## Example

**Program to illustrate the working of our solution,**

#include<iostream> using namespace std; int calcPassCount(int stu[], int n) { int maxMarks = stu[0]; for(int i = 1; i < n; i++){ if(stu[i] > maxMarks) maxMarks = stu[i]; } int bonusMarks = 100 − maxMarks; int passCount = 0; for(int i=0; i<n; i++) { if(stu[i] + bonusMarks >= 50) passCount ++; } return passCount; } int main() { int stu[] = {45, 32, 78, 10, 53, 67}; int n = sizeof(stu)/sizeof(stu[0]); cout<<"The Maximum students to pass after giving bonus to everybody is "<<calcPassCount(stu, n); return 0; }

## Output

The Maximum students to pass after giving bonus to everybody is 5

- Related Questions & Answers
- Maximum students to pass after giving bonus to everybody and not exceeding 100 marks in C++
- C++ program to find maximum distance between two rival students after x swaps
- C program to find marks of students for boys or girls
- Finding average marks of students for different subjects and display only the highest average marks in MySQL
- Program to find maximum average pass ratio in Python
- Program to find maximum element after decreasing and rearranging in Python
- C++ code to find position of students after coding contest
- MySQL new user access denied even after giving privileges?
- Truncating multiple strings after 100 characters in ABAP
- C++ Program to find array after removal from maximum
- Program to find maximum binary string after change in python
- How to write on selection screen after giving any user input in SAP ABAP
- How do you imagine world after 100 years?
- C++ program to count minimum how many minutes after there will be no new angry students
- Python program to print all Happy numbers between 1 and 100