Calculate the CGPA and CGPA % of marks obtained by a Student in N subjects | Javascript program to calculate the CGPA and CGPA percentage of a student ; Variable to store the grades in every subject ; Variables to store CGPA and the sum of all the grades ; Computing the grades ; Computing the sum of grades ; Computing the CGPA ; Driver Code
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 + " " ) ; document . write ( " " + ( cgpa * 9.5 ) . toFixed ( 2 ) ) ;