Calculate the CGPA and CGPA % of marks obtained by a Student in N subjects

Given an array arr[] of size N which contains the marks of a student in N subjects, the task is to calculate the CGPA and the CGPA percentage of the student. 
Note: Consider all marks to be out of 100, for each subject.

CGPA(Cumulative Grade Point Average) is the systematic arrangement in the educational stream to get an average of grade points.

Examples:

Input: arr[] = {90, 80, 70, 80, 90} 
Output: CGPA = 8.2, Percentage = 77.89 
Explanation: 
The grade in each subject respectively out of 10 is {9, 8, 7, 8, 9}. 
The CGPA is the average of all the grades = (9 + 8 + 7 + 8 + 9) / 5 = 8.2 
The percentage of this CGPA is 77.89.

Input: arr[] = {90, 90, 90, 80, 85} 
Output: CGPA = 8.7, Percentage = 82.65



Approach: In this article, the CGPA is calculated on a scale of 10.

  • Input the array from the user containing the marks of the student in N subjects.
  • Since the scale is on 10, divide marks in every subject by 10 to find the GPA of the student in each subject.
  • The average of all the GPA’s yield the overall CGPA of the student.
  • After finding the CGPA, the CGPA percentage can be calculated by the formula:
CGPA% = CGPA * 9.5
  • This is a general formula for a scale of 10. However, if the entire calculation is made on a scale of 4, this 9.5 is thereby multiplied by 2.5 and the CGPA percentage is found by multiplying with 23.75.

Below is the implementation of the above approach:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to calculate the CGPA
// and CGPA percentage of a student
#include<bits/stdc++.h>
using namespace std;
 
double CgpaCalc(double marks[], int n)
{
    // Variable to store the grades in
    // every subject
    double grade[n];
 
    // Variables to store CGPA and the
    // sum of all the grades
    double cgpa, sum = 0;
 
    // Computing the grades
    for(int i = 0; i < n; i++)
    {
       grade[i] = (marks[i] / 10);
    }
 
    // Computing the sum of grades
    for(int i = 0; i < n; i++)
    {
       sum += grade[i];
    }
 
    // Computing the CGPA
    cgpa = sum / n;
 
    return cgpa;
}
 
// Driver code
int main()
{
    int n = 5;
    double marks[] = { 90, 80, 70, 80, 90 };
 
    double cgpa = CgpaCalc(marks, n);
         
    cout << "CGPA = ";
    printf("%.1f\n", cgpa);
    cout << "CGPA Percentage = ";
    printf("%.2f", cgpa * 9.5);
}
 
// This code is contributed by Bhupendra_Singh

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to calculate the CGPA
// and CGPA percentage of a student
 
import java.util.Scanner;
class CGPA {
 
    public static double CgpaCalc(double[] marks, int n)
    {
        // Variable to store the grades in
        // every subject
        double grade[] = new double[n];
 
        // Variables to store CGPA and the
        // sum of all the grades
        double cgpa, sum = 0;
 
        // Computing the grades
        for (int i = 0; i < n; i++) {
            grade[i] = (marks[i] / 10);
        }
 
        // Computing the sum of grades
        for (int i = 0; i < n; i++) {
            sum += grade[i];
        }
 
        // Computing the CGPA
        cgpa = sum / n;
 
        return cgpa;
    }
 
    // Driver code
    public static void main(String args[])
    {
 
        int n = 5;
        double[] marks
            = { 90, 80, 70, 80, 90 };
 
        double cgpa = CgpaCalc(marks, n);
 
        System.out.println(
            "CGPA = " + cgpa);
        System.out.println(
            "CGPA Percentage = "
            + String.format("%.2f", cgpa * 9.5));
    }
}

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to calculate the CGPA
# and CGPA percentage of a student
def CgpaCalc(marks, n):
 
    # Variable to store the grades in
    # every subject
    grade = [0] * n
   
    # Variables to store CGPA and the
    # sum of all the grades
    Sum = 0
   
    # Computing the grades
    for i in range(n):
       grade[i] = (marks[i] / 10)
   
    # Computing the sum of grades
    for i in range(n):
       Sum += grade[i]
   
    # Computing the CGPA
    cgpa = Sum / n
   
    return cgpa
   
# Driver code
n = 5
marks = [ 90, 80, 70, 80, 90 ]
 
cgpa = CgpaCalc(marks, n)
       
print("CGPA = ", '%.1f' % cgpa)
print("CGPA Percentage = ", '%.2f' % (cgpa * 9.5))
 
# This code is contributed by divyeshrabadiya07

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to calculate the CGPA
// and CGPA percentage of a student
using System;
 
class GFG{
 
public static double CgpaCalc(double[] marks,
                              int n)
{
     
    // Variable to store the grades in
    // every subject
    double []grade = new double[n];
 
    // Variables to store CGPA and the
    // sum of all the grades
    double cgpa, sum = 0;
 
    // Computing the grades
    for(int i = 0; i < n; i++)
    {
        grade[i] = (marks[i] / 10);
    }
 
    // Computing the sum of grades
    for(int i = 0; i < n; i++)
    {
        sum += grade[i];
    }
 
    // Computing the CGPA
    cgpa = sum / n;
 
    return cgpa;
}
 
// Driver code
public static void Main(String []args)
{
    int n = 5;
    double[] marks = { 90, 80, 70, 80, 90 };
    double cgpa = CgpaCalc(marks, n);
 
    Console.WriteLine("CGPA = " + cgpa);
    Console.WriteLine("CGPA Percentage = {0:F2}",
                      cgpa * 9.5);
}
}
 
// This code is contributed by Amit Katiyar

chevron_right


Output: 

CGPA = 8.2
CGPA Percentage = 77.90

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.




My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.