# Math Help - Loop Statements

1. ## Loop Statements

hello..i've been searching for some websites that could help me in this thing. i am very new to things like pseudocode, although it's been like 4 months already..i couldnt understand a single thing. i hope someone could help me. Especially to those who are computer genius. Please..could someone help me.. i am okay when the teacher explains it. but when it comes to excercise..i am totally blank. so here's the question:

Construct a flowchart or pseudocode that reads an integer x and a number y. THe integer x should be between 1 to 10 and the numbe y should have x digits. The number y is displayed in two parts diagonally beginning with the leftmost unit digit. The process continues untill the rightmost digit is reached.

The example of the user interface screen for x=4 is as shown below:
Please jey in an integer x (1-10) : 4
Please key in any 4-digit number y: 1956
1 956
19 56
195 6

I really hope there's someone could tutor me..

2. ## Pseudocode

Hello blurryqueen
Originally Posted by blurryqueen
hello..i've been searching for some websites that could help me in this thing. i am very new to things like pseudocode, although it's been like 4 months already..i couldnt understand a single thing. i hope someone could help me. Especially to those who are computer genius. Please..could someone help me.. i am okay when the teacher explains it. but when it comes to excercise..i am totally blank. so here's the question:

Construct a flowchart or pseudocode that reads an integer x and a number y. THe integer x should be between 1 to 10 and the numbe y should have x digits. The number y is displayed in two parts diagonally beginning with the leftmost unit digit. The process continues untill the rightmost digit is reached.

The example of the user interface screen for x=4 is as shown below:
Please jey in an integer x (1-10) : 4
Please key in any 4-digit number y: 1956
1 956
19 56
195 6

I really hope there's someone could tutor me..
Welcome to Math Help Forum!

I don't know if you are expected to validate the data input (in other words to check that x lies between 1 and 10, and that y has x digits), but the pseudocode I've written here assumes that you are. If you haven't covered this sort of data validation, then you can simplify the program by omitting the loops after the two input statements.

Code:
begin
input x
loop until (x > 1) and (x < 10)
input x
end loop
input y
loop until y has x characters
input y
end loop
i = 1
loop until i = x
output leftmost i characters of y
output " "
output rightmost (x - i) characters of y
output newline character
i = i + 1
end loop
end

You'll see that the first input statement comes before the validation loop that checks that x is in the right range (and I'm assuming that x lies strictly between 1 and 10; x = 1 would not produce any output). If the first input value of x is OK, then the loop won't be executed at all. But if x is not valid, then you'll stay in that loop until it is.

The second validation loop, following the input y statement, works in the same way.

i is a counter for the main loop. It is set equal to 1 before the loop starts; the loop then outputs the required string of characters, and a newline, before incrementing the value of i. Exit from the loop will occur when i = x. (In the example you gave, outputs occur for i = 1, 2 and 3, but not for i = 4.)

I haven't included detailed instructions about how the program would validate the length of y (checking that it has x characters), or how it would output the leftmost or rightmost n characters. Nearly all programming languages will have functions that will allow you to do this in a single line of code.

I hope that you understand how this works. Let us know if you need any further explanation.