mardi 3 septembre 2019

How to make a frame pattern width rows, columns, and thickness input?

My lecturer gave me a homework to make a "*" pattern that looks like a picture frame. It kinda same like the hollow square one but it's harder. It should work with any given input in length, width, and thick.

note:If statement is NOT ALLOWED.

Example input: length:10 width:8 thick:2

output:



** ** ** ** ** ** ** **



The plan is to split it into three parts 1st part



2nd part

** ** ** ** ** ** ** **

3rd part (the same as the 1st part)



I know for this case the first part is to make two nested loop. But I got confused on making the second and the third part.

I've know how to make a square before which looks like this

for (int i = 1; i <= p; i++)
{
    for (int j = 1; j <= l ; j++)   
    {
        cout << "*";
    }
    cout << endl;
}

For the second part i knew there will be more loops included but i can't sem to find the solution.

the third part generally looks the same as the first one.

The output should looks like this



** ** ** ** ** ** ** **



If anyone can explain how to do it it'll be appreciated. Thanks!

Aucun commentaire:

Enregistrer un commentaire