Calculate the CGPA and CGPA % of marks obtained by a Student in N subjects
Last Updated :
10 Nov, 2021
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++
#include<bits/stdc++.h>
using namespace std;
double CgpaCalc( double marks[], int n)
{
double grade[n];
double cgpa, sum = 0;
for ( int i = 0; i < n; i++)
{
grade[i] = (marks[i] / 10);
}
for ( int i = 0; i < n; i++)
{
sum += grade[i];
}
cgpa = sum / n;
return cgpa;
}
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);
}
|
Java
import java.util.Scanner;
class CGPA {
public static double CgpaCalc( double [] marks, int n)
{
double grade[] = new double [n];
double cgpa, sum = 0 ;
for ( int i = 0 ; i < n; i++) {
grade[i] = (marks[i] / 10 );
}
for ( int i = 0 ; i < n; i++) {
sum += grade[i];
}
cgpa = sum / n;
return cgpa;
}
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 ));
}
}
|
Python3
def CgpaCalc(marks, n):
grade = [ 0 ] * n
Sum = 0
for i in range (n):
grade[i] = (marks[i] / 10 )
for i in range (n):
Sum + = grade[i]
cgpa = Sum / n
return cgpa
n = 5
marks = [ 90 , 80 , 70 , 80 , 90 ]
cgpa = CgpaCalc(marks, n)
print ( "CGPA = " , '%.1f' % cgpa)
print ( "CGPA Percentage = " , '%.2f' % (cgpa * 9.5 ))
|
C#
using System;
class GFG{
public static double CgpaCalc( double [] marks,
int n)
{
double []grade = new double [n];
double cgpa, sum = 0;
for ( int i = 0; i < n; i++)
{
grade[i] = (marks[i] / 10);
}
for ( int i = 0; i < n; i++)
{
sum += grade[i];
}
cgpa = sum / n;
return cgpa;
}
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);
}
}
|
Javascript
<script>
function CgpaCalc( marks, n)
{
let grade = Array.from({length: n}, (_, i) => 0);
let cgpa, sum = 0;
for (let i = 0; i < n; i++)
{
grade[i] = (marks[i] / 10);
}
for (let i = 0; i < n; i++)
{
sum += grade[i];
}
cgpa = sum / n;
return cgpa;
}
let n = 5;
let marks
= [ 90, 80, 70, 80, 90 ];
let cgpa = CgpaCalc(marks, n);
document.write(
"CGPA = " + cgpa + "<br/>" );
document.write(
"CGPA Percentage = " + (cgpa * 9.5).toFixed(2));
</script>
|
Output:
CGPA = 8.2
CGPA Percentage = 77.90
Time Complexity: O(n)
Auxiliary Space: O(n)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...