Page 104 - Computer Science Class 11 Without Functions
P. 104
Finally, suppose you are required to find the average marks of students in a class. The marks obtained by different
students are entered by the user one by one, and the end of the input is indicated by entering a negative integer. To
deal with situations when you do not know in advance the number of times a loop is to be executed, the programming
languages provide a while construct. Using a while-loop, let us develop a pseudocode to output the average
marks of students. As we do not know the number of students, we need to keep count of the number of students
(say, nStudents). To begin with, we set
nStudents = 0
Further, we need to sum the marks (say, sumMarks) obtained by the students. Again set
sumMarks = 0
Next, while the user enters marks >0, we continue to increment the student count (nStudents), add marks to
the accumulated sum of marks (sumMarks), and read marks for the next student. Finally, we divide sumMarks by
nStudents to get average marks and report the result to the user. We present the foregoing discussion in the form
of pseudocode:
sumMarks = 0
nStudents = 0
Input marks
while marks >0:
nStudents = nStudents + 1
sumMarks = sumMarks + marks
Input marks
end-while
average = sumMarks/nStudents
print(average)
Let's Summarise
Ø Programming language is a language that a computer understands.
Ø Program (code) is a sequence of instructions in a programming language for solving a problem.
Ø The process of dividing a complex problem into subproblems, solving the subproblems, and merging the
solutions to the subproblems to solve the original problem is called the modular approach.
Ø An Algorithm is a sequence of steps to be followed in solving a problem.
Ø A Flowchart is a pictorial representation of an algorithm. Some common symbols used in a flowchart are as
follows:
Symbol Name Symbol usage Description
Start/Stop Used to depict the start and stop of an algorithm
Process Used to depict some arithmetic operation
Input/Output Used to depict Read/Input and Write/Print
102 Touchpad Computer Science-XI

