![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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++
In this tutorial, we will be discussing a program to find maximum students to pass after giving bonus to everybody and not exceeding 100 marks.
For this we will be provided with an array containing marks of N students. Our task is to get more student pass the exam (50 marks required) by giving each student the same amount of bonus marks without any student exceeding 100 marks.
Example
#include<iostream> #include<algorithm> using namespace std; int check(int n, int marks[]) { int* x = std::max_element(marks,marks+5); int bonus = 100-(int)(*x); int c = 0; for(int i=0; i<n;i++) { if(marks[i] + bonus >= 50) c += 1; } return c; } int main() { int n = 5; int marks[] = {0, 21, 83, 45, 64}; cout<<check(n, marks)<<endl; return 0; }
Output
3
Advertisements