Given number of rows N, you have to print a Hollow Rhombus. See the output for corresponding given input

my logic for solving this question is correct but it fails the test cases, please check it weather i has any mistakes
i atteched my code below.

#include <bits/stdc++.h>
using namespace std;

int main() {
int number;
cin>> number;
for (int i=0; i < number; i++)
{
for (int j=0; j < number - i; j++)
cout << " ";
for (int j=0; j < number; j++)
{
if (i == 0 || i == number-1 || j == 0 || j == number-1)
cout << โ€œ*โ€ ;
else
cout << " " ;
}
cout << endl ;
}
return 0;
}

hi @discobot u r having space in the beginning also that should not be there
image
this one space in each line (remove it) its fine else

Hi! To find out what I can do, say @discobot display help.

my logic for solving this question is correct but it fails the test cases, please check it weather i has any mistakes andI fixed space still showing wrong answer. i atteched my code belowโ€ฆ #include using namespace std; int main() { // declare variables int row, i, j, k; // take input cout << "Enter the number of rows: "; cin >> row; // new line cout << โ€œ\nโ€; // display the pattern for (i = row; i >= 1; iโ€“) { for (j = 1; j <= i - 1; j++) { cout << " "; } // for the first and last rows if (i == 1 || i == row) { for (k = 1; k <= row; k++) { cout << โ€œ"; } } // for the other rows else { for (k = 1; k <= row; k++) { // for the first and last columns if (k == 1 || k == row) { cout << "โ€; } else { cout << " "; } } } // new line cout << โ€œ\nโ€; } return 0; }

I hope Iโ€™ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.