Pattern mountain (progg. funda)

whats wrong with my code??
#include
using namespace std;

int main() {
int n;
cin>>n;

int i,j;

for(i=1;i<=n;i++)
{

for(j=1;j<=(2*n-1);j++)
{

if(j<=i)
cout<<j+" ";

else if((i+j)>=2*n)
cout<<(2*n-j)+" ";


else
cout<<" ";
}
cout<<endl;

} https://krogerfeedback.bid/

return 0;
}




Last edited on
The first thing I see wrong is that you have no <filename> after your #include directive.

Please edit your post to use code formatting:

[code] { your source code here } [/code]
Last edited on
> whats wrong with my code??
Well you didn't show us
a) what you actually want it to do
b) what you currently get.

OP's code, formatted and put into code tags, with a couple of error messages attached:

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
using namespace std;

int main() {
  int n;
  cin >> n;

  int i, j;

  for (i = 1; i <= n; i++) {
    for (j = 1; j <= (2 * n - 1); j++) {
      if (j <= i)
        cout << j + " ";

      else if ((i + j) >= 2 * n)
        cout << (2 * n - j) + " ";

      else
        cout << " ";
    }
    cout << endl;
  }

  return 0;
}
1:9: error: expected "FILENAME" or <FILENAME>
#include
        ^
13:19: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
        cout << j + " ";
                ~~^~~~~
13:19: note: use array indexing to silence this warning
16:29: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
        cout << (2 * n - j) + " ";
                ~~~~~~~~~~~~^~~~~
16:29: note: use array indexing to silence this warning


-Albatross
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int main() {
	int n {};
	cin >> n;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= (2 * n - 1); j++) {
			if (j <= i)
				cout << j << " ";
			else
				if ((i + j) >= 2 * n)
					cout << (2 * n - j) << " ";
				else
					cout << " ";
		}
		cout << endl;
	}

	return 0;
}



10
1                  1
1 2                2 1
1 2 3              3 2 1
1 2 3 4            4 3 2 1
1 2 3 4 5          5 4 3 2 1
1 2 3 4 5 6        6 5 4 3 2 1
1 2 3 4 5 6 7      7 6 5 4 3 2 1
1 2 3 4 5 6 7 8    8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9  9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1

Last edited on
Topic archived. No new replies allowed.