Page 104 - Computer Science Class 11 With Functions
P. 104
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
Arrow Used to connect shapes depicting the flow of control
Decision box Represents a condition that may yield True or False.
102 Touchpad Computer Science-XI

