Problem Statements:
1. Given numerical grades and credits(weightage) of n subjects find CPI of the student. The grades are as follows:
10
9
8
7
6
0: Fail
Accept the credits for each subject from user and calculate the CPI of the student.
e.g. Grades obtained by a student in subjects s1, s2, s3, s4, s5 are 9,10,8,7,9 respectively
Credits for s1, s2, s3, s4, s5 are 7,6,5,8,8
CPI = Total grades obtained by a student(weighted sum)/Total no of credits
= ( 9 * 7 + 10 * 6 + 5 * 8 + 8 * 7 + 8 * 9 ) / ( 7 + 6 + 5 + 8 + 8 )
Sample run:
Enter the number of subjects: 5
Subject1:
Credits: 7
Grades:9
Subject2:
Credits:6
Grades:10
Subject3:
Credits:5
Grades:8
Subject4:
Credits:8
Grades:7
Subject5:
Credits:8
Grades:9
CPI = 8.55
2. Given a number n, find how many bits are required to represent the number in binary.
Generalize it for any base b.
Do not use logarithm function.
e.g. base = 2 n = 16 o/p = 5 bits.
base = 3 n = 47 o/p = 4 bits
Representation of numbers in binary:
We usually use decimal no system where base is 10. i.e. here, weights assigned to each position in the number are powers of 10.
e.g. 1549 = 1 * (10 raised to 3) + 5 * (10 raised to 2)+ 4*(10 raised to 1) + 9* (10 raised to 0)
Similarly, we can use binary number system where base is 2 and instead of 0-9 digits, we use only 0 and 1.
e.g. 25 in binary is represented as 11001
25 = 1*(2 raised to 4) + 1*(2 raised to 3) + 0*(2 raised to 2) + 0*(2 raised to 1) + 1*(2 raised to 0)
The same way we can use any base b, the digits used to represent the number in that number system will be from 0 to (b-1)