|
|
|
|
eXercise #8
Iteration using
WHILE...DO
- Write a simple
program which accepts a line of input from the user and which reports
the number of characters typed.
- Write a simple
program which accepts a line of characters in a similar fashion to
the previous question, from the keyboard and which returns to the
screen the number of spaces, vowels and consonants in the typed line.
A case statement may prove helpful.
- Write a small
program for the following task. The user inputs a number between 0
and 50 and the machine prints that many asterisks on the next line.
Note that you should use a while loop to solve this problem.
- Write a small
code fragment which asks the user for an integer and which then reports
the whole number power of 2 which this number is equal to or exceeds.
For example, if the user types in the number 1000, the machine should
respond with the value 9 because 2 to the power of 9 = 512 which is
less than 1000 but 2 to the power of 1O = 1024 and this is greater
than 1000.
- Convert the following
code fragment to one which uses a while statement. Note that i is
an integer variable. Note also that this fragment outputs the squares
from 1 to 20 inclusive. Make certain your code also does this.
i := 0;
repeat
i := i+l;
showmessage(inttostr(i*i)))
until i*i>=20
|
|
|
|
|
|
|