How should i go about writing this task?

1) Write a program that prints on the screen
the following structures for number n of lines
given by user:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

1
2 4
3 6 9
4 8 12 14
5 10 15 20 25

0
3 6
6 9 12
9 12 15 18
12 15 18 21 24
15 18 21 24 27 30

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  #include <iostream>
#include <cstdlib>
#include <stdio.h>

using namespace std;

int main () {
	int a;
	int b;
	cout<<"Choose the structure of lines(1,2,3)";
	cout<<endl;
	cin>>a;
	for (a=1;a<6;a+1)
		{
			cout<<b;
		}
	
}

This is what I have so far.
Last edited on
So obviously you need to calculate b before line 15. For each structure you need to calculate b in a for loop. At the end of a loop iteration for variable a, you need to output a new line cout<<endl;
For structure 1, on each line b is all integers from 1 to (including) a
For structure 2, on each line b is a, multiplied with 1,2,..., up to a
For structure 3, on each line b is 3*(a-1), then add 3 for each iteration over b, from 1 to a
To make it look nice, when you output b, output an empty space after that as well cout<<b<<" ";
Last edited on
Topic archived. No new replies allowed.