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
1
2
3
4
5
6
7
  int=5
for (int=0,i<x;i++)
for(int j=0;j<x;j++)
cout<<"O";
cout<<"/n"
}
//some codes over here 

the first was already done,
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

Please help out, seriously I'm failing my programming class
though it isn't related to my course(which is architecture)
and i need to maintain my grades to keep my scholarship.
please help TwT
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.

Here's your Fibonacci one:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>

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:

1
2
3
4
5
6
7
8
9
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.