What will be the loop for this?

Hello what will be the loop coding for getting this out?
Last edited on
Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
for (int x = 0; x < 5; x++)
	{
		for (int y = 1; y < x + 1 ; y++)
		{
			printf(" ");
		}

		for (int y = 5; y > x ; y--)
		{
			printf("*");
		}
	printf(" \n");
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

using namespace std;
int main ()
{ int max_row=5;// you can chang it value
  for(int i=0;i<max_row;i++){
        for(int j=0;j<max_row;j++){
            if(j>=i){ cout<<"*";}else{cout<<" ";}

        }
    cout<<endl;
  }
  return 0;
}
Last edited on
Getting error in c++

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

int main()
{
	for (int x = 0; x < 5; x++)
	{
		for (int y = 1; y < x + 1; y++)
		{
			cout << " ";
		}

		for (int y = 5; y > x; y--)
		{
			cout << "*"
		}
		cout << endl;
	}
}
Thank you very much man sujitnag
Topic archived. No new replies allowed.