|
|
|||||||
|
|
|||||||
|
·
Lecture No. 4 |
|||||||
|
Sample Program |
Examples of
Expressions |
Use of Operators |
|
|
|||
|
|||||||
|
Tips |
|
|
|
|
|||
|
|||||||
|
|
|||||||
|
Problem statement: Calculate
the average age of a class of ten students. Prompt the user to enter the age
of each student. Solution: Lets
first sort out the problem. In the problem we will take the ages of ten
students from the user. To store these ages we will use ten variables, one
for each student’s age. We will take the ages of students in whole numbers
(in years only, like 10, 12, 15 etc), so we will use the variables of data
type int. The variables
declaration statement in our program will be as follow: int age1, age2, age3, age4, age5, age6, age7, age8, age9, age10; We
have declared all the ten variables in a single line by using comma separator
(,). This is a short method to declare a number of variables of the same data
type. |
|||||||
|
|
|
|
NEXT |
||||