Download For Loop Tasks

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
For Loop tasks
For each of the following, write a program which includes suitable FOR loops. FULLY COMMENT
YOUR CODE.
1) Display the message “AS Computing is Cool” 25 times.
2) Ask a user for a message and a number of times they would like the message repeating. Display
the message and the instance. E.g:
1 Hello there
2. Hello there
3. Hello there etc.
3) Ask the user to enter 5 numbers. Display the largest number at the end. (HINT: You only ever
need to store two numbers and remember the largest of the two!)
4) Ask the user how many stars they would like in a row. Then display the number of stars in a row.
5) Expand solution in question 5 to produce a filled rectangle of stars. It will need to ask the user
how many rows they would like. Hint: You will need a FOR Loop within a loop. It’s a challenge!
6) Ask the user for a number between 1 and 12. If the number is between 1 and 12, enter a loop
which produces the times table upto 12. E.g. If 4 was entered it would display:
1x4=4
2x4=8
3 x 4 = 12
…
12 x 4 = 48
7) Write a program to find the total of all odd numbers between 1 and 99 (hint: STEP)
8) CHALLENGE: Request a sentence from a user. Count how many times (if any) the letter E
occurs and display this on screen.
9) For each of the following, write down what the output is:
I=0
For I = 1 to 4
Console.writeline(“Pass #” & str(i))
Next i
I=0
For I = 1 to 8 Step 2
Console.write(i)
Next i
Output:
Output:
J=0
For j = 2 to 8 Step 2
Console.write(j & “ “)
Next j
Dim countdown as integer
For countdown = 10 to 1 Step -1
Console.writeline(countdown)
Next countdown
Console.write (“ who do we appreciate?”)
Console.writeline(“Blast off”)
Output:
Output:
I=0
Console.writeline(“Enter a number”)
For I = 3 to 5 step .25
Console.writeline(i)
Next i
Num = console.readline()
Console.writeline(i)
If num <= 10 then
For I = 1 to 6 step 2
Num = num +1
Console.writeline(i)
Next i
Else
Console.writeline(num+10)
End If
Output:
I=0
Output: