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

Information Technology Loops

This document provides programming worksheets and exercises on using loops in Pascal. It includes examples of using for loops and while loops to calculate sums of natural numbers, display terms, calculate averages, find highest marks, and other numerical calculations. Students are asked to write programs using loops to output results for different test data and conditions. Loops are a fundamental programming concept for repetition and iteration.

Uploaded by

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

Information Technology Loops

This document provides programming worksheets and exercises on using loops in Pascal. It includes examples of using for loops and while loops to calculate sums of natural numbers, display terms, calculate averages, find highest marks, and other numerical calculations. Students are asked to write programs using loops to output results for different test data and conditions. Loops are a fundamental programming concept for repetition and iteration.

Uploaded by

Riah Tiffany
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Information Technology

Programming Worksheet : Loops

IF statements review

1. Write a program to print the message ‘Your tuition is free’ if the student scores over 85
marks in the entrance examination.

2. A store uses the following policy to award discounts. If the customer purchases products
costing more then $500 she is given a discount of 10%, otherwise she is given a discount of
2%. Write a program to compute the discount a customer will receive based on the purchase
she makes.

Do the following programs using for loops as well as using while loops.

1. Write a pascal program to find the sum of first 10 natural numbers.


Expected Output :
The first 10 natural number is :
1 2 3 4 5 6 7 8 9 10
The Sum is : 55
2. Write a program in pascal to display n terms of natural number and their sum.
(n means that the user enters the number)
Test Data : 7
Expected Output :
The first 7 natural number is :
1234567
The Sum of Natural Number up to 7 terms : 28

Some more practice.

1. Using a for loop, write a program which reads a number that represents the number of
students who took an examination. The program should count the number of students who
failed. The pass mark is 60. Output the number passed, number failed and the number of
students who took the exam.
2. Using a for loop, write a program to calculate and print the average score for each student in
a class of 25. Each student was given three tests.
3. Using a while loop, write a program where the user enters the marks of students terminated
by 999. Find and print the average and the highest mark.
3. Consider the following while loop:
begin
a: = 0;
while a < 5 do
begin
a : = a + 3;
writeln(a, ‘is less than 5’);
end;
end.

How many times would the program go through the loop?

4. Consider the following segment of code:

begin
For a:= 1 to 5 do
writeln (‘Help’);
writeln(‘me’);
end.

Is the above statement correct? Give reason for your answer.

5. Consider the following segment of code:


begin
a:= 0;
repeat
a:= a + 1;
writeln(‘the number is’ , a)
until a>5;

In the third repetition of the repeat-until segment, what is printed out?

6. Using WHILE loop,


Write a program where the user enters the marks of students terminated by 999. Find and
print the average and the highest mark.

7. Using FOR loop,


Write a program to enter 10 numbers and output the highest and lowest numbers
appropriately.
8. Write a program that tests to see if numbers are less than 20 using the while do loop in
Pascal. Within the loop add 2 to each number and output the result.

9. Write a program that accepts the scores of 20 students using a for loop and adds each
mark to a variable name totalMark. After the loop, out put the total mark.

You might also like