0% found this document useful (0 votes)
6 views

Simple for Next Loop (Format 1) Notes With Practice Questions

Uploaded by

Fari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Simple for Next Loop (Format 1) Notes With Practice Questions

Uploaded by

Fari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Simple For Next Loop (Format 1) Notes with Practice questions

NOTE: Do Your Assignment Work in School Registers, Every Assignment carries 1 mark, if all Assignments will be submitted on time, and 1 bonus
mark will be awarded.

Firstly, Let us revise the whole concept by solving the first part given below

Solved Example

(a) Fuel economy for a car is found using the formula:

What would be the Fuel Economy of a car travelling 40 km on 10 liters of fuel? [1]

(b) The Fuel Economy for 1000 cars is to be calculated using the formula in Question 16(a).

Write an algorithm, using pseudo code or otherwise, which inputs the Distance Travelled (km) and the Fuel Used (liters) for 1000 cars. The Fuel
Economy for each car is then calculated and the following outputs produced:

• Fuel Economy for each car


• Average (mean) Fuel Economy for all of the cars input
• The best Fuel Economy (i.e. highest value)
• The worst Fuel Economy (i.e. lowest value)

Solution

a) Fuel Economy <- 40 (km)/10 (Liters)


Fuel economy <- 4 (km/liters)
Before we start solving the b part, let us revise the Format 1.

As we know that:

Format 1

Initialize

For count <- 1 to N

Input

Formula Calculation

Output formula Results

Totaling (total <- total + . . . . . . .)

Decision with counting (count2 <- count2 +1)

Extreme values

Next Count

Average <- total/N

Percentage <- (count2/N)*100

Output average

Output percentage

>>>>>>>>>>>>>>>>>>>>>>>>>>>
Now we know the format 1, we’ll write the pseudo code for the above problem (b part) according to Format 1 and we’ll also mention which part
of Format 1 is correlating with the Pseudo Code.

Fuel_economy <- 0

total <- 0 initialize

worst <- 1000

best <- -1000

For count <- 1 to 1000 for count <- 1 to N

Input fuel Input

Input distance

fuel_economy <- distance/fuel Formula calculation

Output fuel_economy Output Formula Results

total <- total + fuel_economy Totaling

If fuel_economy > best then

Best <- fuel_economy

Endif Extreme Values

If fuel_economy < worst then

worst <- fuel economy

Endif

Next Next
Avg <- total/1000 average <- total/N

Output avg Output

Output best, worst

Note that not all of the contents of format 1 are correlated with the pseudo code, as they were not required. Only desired contents should be
used, which we can obtain by carefully reading the problem.

Assignment Questions,
Q.1 Correlate the Format 1 with the solved ‘b’ part of the problem given below. (Hint: look at the above given example)

(a) A formula for calculating the body mass index (BMI) is:

Calculate the BMI for a person whose weight is 80kg and height is 2 metres. [1]

(b) Using pseudocode or otherwise, write an algorithm that will input the ID, weight (kg) and
height (m) of 30 students, calculate their body mass index (BMI) and output their ID,BMI and a comment as follows:

A BMI greater than 25 will get the comment ‘OVER WEIGHT’, a BMI between 25 and 19 (inclusive) will get ‘NORMAL’ and a BMI less than 19 will
get ‘UNDER WEIGHT’.

Solution

weight <- 1

height <- 1

bmi <- 0

For count <- 1 to 30


Input id, height, weight

bmi <- weight / (height * height)

Output id, bmi

If bmi > 25 Then

Output ‘OVERWEIGHT’

Endif

If bmi <= 25 and bmi >= 19 Then

Output ‘NORMAL’

Endif

If bmi < 19 Then

Output ‘UNDERWEIGHT’

Endif

NEXT

Q.2 Correlate the Format 1 with the solved part of the problem given below.

Temperatures (°C) are being collected in an experiment every hour over a 200 hour period. Write an algorithm, using pseudo code or otherwise,
which inputs each temperature and outputs

• how many of the temperatures were above 20°C


• how many of the temperatures were below 10°C
• The lowest temperature that was input

Solution
temp <- 0

totalhigh <- 0

totallow <- 0

lowest <- -1000

For count < 1 to 200

Input temp

If temp >= 20 then totalhigh <- totalhigh +1

Endif

If temp <= 10 then totallow <- totallow +1

Endif

If temp > lowest then lowest <- lowest

Endif

Next

Output totalhigh

Output totallow

Output lowest

Now, solve these Problems given below all by yourself With the Help of Format 1.

Q3
(a) A car’s speed is measured between points A and B, which are 200 km apart.

The final speed of the car is calculated using the formula:

What is the final speed of a car if it takes 2 hours to get from A to B?

(b) Write an algorithm, using pseudo code, which inputs the times for 500 cars, calculates the final speed of each car using the formula in part
(a), and then outputs:

• the final speed for ALL 500 cars


• the slowest (lowest) final speed
• the fastest (highest) final speed
• The average final speed for all the cars

Q4

A school is doing a check on the heights and weights of all its students. The school has 1000 students.

Write an algorithm, using pseudo code, which

• inputs the height and weight of all 1000 students


• outputs the average (mean) height and weight
Q5

(a) Write an algorithm, using pseudo code, which:

• inputs 50 numbers
• outputs how many of the numbers were > 100

(b) Write an algorithm, using pseudo code, which:

• inputs 100 numbers


• finds the average of the input numbers
Outputs the average

You might also like