Skip to content
Related Articles

Related Articles

Improve Article
Program to find minimum number of lectures to attend to maintain 75%
  • Difficulty Level : Medium
  • Last Updated : 27 May, 2021

Consider the subject Data Structures for which the total number of classes held till present date is M, and some students attend only N  out of these classes. Find the minimum number of lectures they have to attend so that their 

*** QuickLaTeX cannot compile formula:
75\%  

*** Error message:
Cannot connect to QuickLaTeX server: cURL error 28: Operation timed out after 40001 milliseconds with 0 bytes received
Please make sure your server/PHP settings allow HTTP requests to external resources ("allow_url_fopen", etc.)
These links might help in finding solution:
http://wordpress.org/extend/plugins/core-control/
http://wordpress.org/support/topic/an-unexpected-http-error-occurred-during-the-api-request-on-wordpress-3?replies=37

attendance is maintained. 

Examples:  

Input : M = 7 and N = 6 
Output : 0 lectures to attend 
As 7 classes have been held till present, out of which 6 classes have been attended, which is greater than 
75%, so no more lectures to attend

Input : M = 9 and N = 1 
Output : 23 lectures to attend 
Out of 9 classes, only 1 class is attended. After 23 more classes, a total of 1+23 = 24 classes 
have been attended and the total number of classes held = 9+23 = 32. So 24/32 = 75%. Hence 23 is 
the minimum value.



Solution: 
Using the formula, 

*** QuickLaTeX cannot compile formula:
Ceil\left (\frac{(0.75*M)-N}{0.25} \right )  

*** Error message:
Cannot connect to QuickLaTeX server: cURL error 28: Operation timed out after 40001 milliseconds with 0 bytes received
Please make sure your server/PHP settings allow HTTP requests to external resources ("allow_url_fopen", etc.)
These links might help in finding solution:
http://wordpress.org/extend/plugins/core-control/
http://wordpress.org/support/topic/an-unexpected-http-error-occurred-during-the-api-request-on-wordpress-3?replies=37

Before applying the formula, first, check whether N by M has 75% or not. If not, then apply the formula 

C++




// C++ Program to find minimum number of lectures to attend
// to maintain 75% attendance
 
#include <cmath>
#include <iostream>
using namespace std;
 
// Function to compute minimum lecture
int minimumLectures(int m, int n)
{
    int ans = 0;
 
    // Formula to compute
    if (n < (int)ceil(0.75 * m))
        ans = (int)ceil(((0.75 * m) - n) / 0.25);
    else
        ans = 0;
 
    return ans;
}
 
// Driver function
int main()
{
    int M = 9, N = 1;
    cout << minimumLectures(M, N);
    return 0;
}

Java




// Java Program to find minimum number of lectures to attend
// to maintain 75% attendance
 
public class GFG {
 
    // Method to compute minimum lecture
    static int minimumLectures(int m, int n)
    {
        int ans = 0;
 
        // Formula to compute
        if (n < (int)Math.ceil(0.75 * m))
            ans = (int)Math.ceil(((0.75 * m) - n) / 0.25);
        else
            ans = 0;
 
        return ans;
    }
 
    // Driver Code
    public static void main(String[] args)
    {
        int M = 9, N = 1;
        System.out.println(minimumLectures(M, N));
    }
}

Python




# Python Program to find minimum number of lectures to attend
# to maintain 75 % attendance
 
import math
 
# Function to compute minimum lecture
def minimumLecture(m, n):
    ans = 0
 
    # Formula to compute
    if(n < math.ceil(0.75 * m)):
        ans = math.ceil(((0.75 * m) - n) / 0.25)
    else:
        ans = 0
    return ans
 
# Driver Code
 
M = 9
N = 1
 
print(minimumLecture(M, N))

C#




// C# Program to find minimum
// number of lectures to attend
// to maintain 75% attendance
using System;
 
class GFG
{
 
// Method to compute minimum lecture
static int minimumLectures(int m, int n)
{
    int ans = 0;
 
    // Formula to compute
    if (n < (int)Math.Ceiling(0.75 * m))
        ans = (int)Math.Ceiling(((0.75 * m) -
                                 n) / 0.25);
    else
        ans = 0;
 
    return ans;
}
 
// Driver Code
public static void Main()
{
    int M = 9, N = 1;
    Console.WriteLine(minimumLectures(M, N));
}
}
 
// This code is contributed
// by anuj_67

PHP




<?php
// PHP Program to find minimum
// number of lectures to attend
// to maintain 75% attendance
 
// Function to compute minimum lecture
function minimumLectures($m, $n)
{
    $ans = 0;
 
    // Formula to compute
    if ($n < ceil(0.75 * $m))
        $ans = (int)ceil(((0.75 * $m) -
                          $n) / 0.25);
    else
        $ans = 0;
 
    return $ans;
}
 
// Driver Code
$M = 9; $N = 1;
echo minimumLectures($M, $N);
 
// This code is contributed
// by anuj_67
?>

Javascript




<script>
    // Javascript Program to find minimum
    // number of lectures to attend
    // to maintain 75% attendance
     
    // Method to compute minimum lecture
    function minimumLectures(m, n)
    {
        let ans = 0;
 
        // Formula to compute
        if (n < Math.ceil(0.75 * m))
            ans = Math.ceil(((0.75 * m) - n) / 0.25);
        else
            ans = 0;
 
        return ans;
    }
     
    let M = 9, N = 1;
    document.write(minimumLectures(M, N));
     
</script>

Output: 

23

 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with industry experts, please refer Geeks Classes Live




My Personal Notes arrow_drop_up
Recommended Articles
Page :