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

Using The FOR Construct Write Instructions For Each of The Following Problems

The document provides examples of control structure problems to solve using FOR and WHILE loops. It includes 10 problems - 5 using FOR loops and 5 using WHILE loops. The problems cover topics like calculating percentages, printing tables, finding highest/lowest values, calculating totals and averages, and tracking inventory.

Uploaded by

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

Using The FOR Construct Write Instructions For Each of The Following Problems

The document provides examples of control structure problems to solve using FOR and WHILE loops. It includes 10 problems - 5 using FOR loops and 5 using WHILE loops. The problems cover topics like calculating percentages, printing tables, finding highest/lowest values, calculating totals and averages, and tracking inventory.

Uploaded by

Yanique Jones
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CONTROL STRUCTURES ACTIVITY SHEET

Using the FOR construct write instructions for each of the following problems.

1. Write a program that reads the result of 10 games played by a team and finds the percentage of games won

by the team. Output the percentage games won.

2. Print a table to find the square and cube of all even numbers between 2 and 20 inclusive.

3. Write an algorithm to enter 10 numbers and output the highest and lowest numbers appropriately labelled.

4. Write an algorithm which finds the total of the numbers 10 to 25 and print the total.

5. Write an algorithm to compute the following expression:

Y1 = 2(2-x2) and Y2 = 2-(2-x2) using values -4 to +4 for the values of x. Print x, Y1 and Y2.

Using the WHILE construct write instructions for each of the following problems.

1. Enter the marks of students terminated by 999. Find and print the average and the highest mark.

2. Write an algorithm to input integers until a sentinel value of 0 is entered; print the sum of all the positive
numbers entered and the sum of all negative numbers entered. The number of positives and negatives must
also be printed.

3. A company gives out bonuses based on the amount of income generated by their sales representatives per
month. Once the income is greater than $5000.00, a bonus of 10% of the generated income is added to the
sales representative’s salary of $4000.00. Write an algorithm to input the sales representative’s number and
income generated; calculate the bonus, and salary plus bonus. Data is terminated by entering the value 000
for the sales representatives number.

4. A supermarket is keeping track of the amount in stock of an item. Write an algorithm to keep track of how
many of the items remain at the end of the day if the initial quantity was 210. Input the quantity bought at
each purchase; calculate the total amount sold and the quantity remaining, if the number of sales and
quantity purchased is not known in advance. Terminate the data by entering 0 for quantity.

5. A resident person leaving their country is required to pay a departure tax of $100.00. However, if the person
is a visitor to the country, an additional $20.00 must be paid. Read in the passenger number, terminated by
0, and whether the passenger is a visitor or resident. Write an algorithm to calculate the total amount of tax
collected for the day.

TRACE TABLE

S = 25
1. What is printed by the following? N=1
WHILE N < 12 DO
S=S–N
PRINT S
R=5 N=N+2
S–6 ENDWHILE
IF S > 5 THEN
T=S*R
ELSE
3. Using numbers 5, 20, 25, 30, -1 for Num and 2,
T = S/R
ENDIF 4, 4, 3 for Rate respectively, what is printed by
PRINT T the following algorithm?

2. What is printed by the following? READ Num


WHILE Num >= 0 DO
READ Rate
Value = Num * Rate/100
PRINT Rate, Num,
Value
8. What is printed by the following algorithm?

X=1
WHILE X <= 8 DO
Y = 2X + (X * X) – 4
4. What is printed by the following algorithm if N PRINT Y
= 47? X=X+2
ENDWHILE

READ N
IF N > 3 THEN 9. What is printed by the following algorithm?
G=1
F=2
ELSE
F=1 Sum = 0
G=2 N = 25
ENDIF WHILE N < 40 DO
FOR J = 1 TO N DO Sum = Sum + N
H = F +G PRINT N, Sum
F=G N=N+4
G=H ENDWHILE
PRINT H
ENDIF

5. What is printed by the following algorithm if B

READ B, C
A=B
B=C
C=A
D=B+C
E=E*C
F=D–B
A=D
B=E
C=F
= 5 and C = 4?PRINT A, B, C, D, E, F

6. What is printed by the algorithm?

FOR X = 1 TO 6 DO
R=X
WHILE R >= 1 DO
PRINT R
R=R–1
ENDWHILE
ENDFOR

7. What is printed by the algorithm if Num is 10?

READ Num
FOR Count = Num to 1
STEP -2 DO
Sum = Count + Num
PRINT Sum
ENDFOR

You might also like