### Exam in loop

so we have 7 sets in an exam due in two days time
we'd modify the code given, but seriously i can't figure each out even though
it's seriously basic
 ``1234567`` `````` int=5 for (int=0,i

while the rest of six sets give me so much trouble
second goes like this,
2. Modify the codes so that it output an NxN hollow box

3. Modify the code to and output an N-diagonal

4. Modify the codes to output an "X"

5. Modify the code and output a right triangle

6. Modify the code to input N-diamond

7. In math there is what we call the fibonacci sequence, make a program that will output the up to the nth fibonacci number

though it isn't related to my course(which is architecture)
and i need to maintain my grades to keep my scholarship.
Last edited on
Wow they make you take programming for architecture?! I feel for you in that case (compared to the usual "do my homework" posters we get) so I'll try to help.

 ``12345678910111213141516171819202122232425`` ``````#include int main() { int range = 20; // this is your "up to nth fibonacci number" int first = 0; int second = 1; int fibonacci = 0; for (int kkk = 0; kkk < range; kkk++) { if (kkk <= 1) { fibonacci = kkk; } else { fibonacci = first + second; first = second; second = fibonacci; } std::cout << fibonacci << " "; } return 0; }``````

You might want to edit the formatting to be consistent with your other codes so it doesn't look like a copy paste. I'll try the others soon if no one else does. Btw, don't use a recursive function (function that calls itself) which is common for the Fib. one - they might think it too advanced at your stage.

Edit:

Btw, when you say the first one was already done, do you mean they wrote that code, because it is all messed up. As I don't know the intention of the first one, my guess is this is how it should be:

 ``123456789`` ``````int x = 5; for (int i=0; i < x; i++) { for(int j=0; j < x; j++) { std::cout << "O"; std::cout << "\n"; } }``````

Last edited on
Those are all pretty simple. Something you might see in the second week of freshmen programming class. What you should do is consider how large you want to make your structure, and the mathematically solve where each object is supposed to go. For the "X" I would define a width, and then a variable z that would increment from 1 to (width / 2), and place a character at (1 + z) and at (width - z) for ever repetition of the for loop. Then, once they reach (width / 2), they star decrementing again until the variable z reaches 1 again, and you'll have printed your big ascii x. All of the rest are pretty similar to that.

EDIT:
Clarifying math.
Last edited on
Topic archived. No new replies allowed.