cant make stars using for loop

i want to make star row and coulombs.
Last edited on
i see.
I think you mean columns, not coulombs.

Please provide and example of the output you're trying to produce.
This should solve your problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

using namespace std;

int main()
{
    int num_of_stars=20;
    for(int i=0;i<num_of_stars;i++){
        cout<<'*';
        }
    cout<<endl;
    return 0;
}
For loops, simple :)
guys i want it like these pattern below

*
***
*****
***
*
guys i found this one but want to make the lower part too.

#include <iostream>
using namespace std;
int main()
{
int i,space,rows,k=0;
cout<<"Enter the number of rows: ";
cin>>rows;
for(i=1;i<=rows;++i)
{
for(space=1;space<=rows-i;++space)
{
cout<<" ";
}
while(k!=2*i-1)
{
cout<<"* ";
++k;
}
k=0;
cout<<"\n";
}
return 0;
}
Haven't you hear about std::cout ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>

using namespace std;

int main()
{
  cout << "*" << "\n";
  cout << "***" << "\n";
  cout << "*****" << "\n";
  cout << "***" << "\n";
  cout << "*" << "\n";

  system("pause");
  return 0;
}
closed account (48T7M4Gy)
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
26
27
28
29
30
#include <iostream>

using namespace std;

int main()
{
    int peak_no = 0;
    int i = 0;
    
    cout << "Enter the number at peak: ";
    cin >> peak_no;
    
    //TOP HALF
    for(i = 0; i < peak_no; i++)
    {
        for(int j = 0; j < i; ++j)
            cout << '*';
        cout  << '\n';
    }
    
    //BOTTOM HALF
    for(i = peak_no; i > 0; i--)
    {
        for(int j = 0; j < i; ++j)
            cout << '*';
        cout  << '\n';
    }
    
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
  int peakRow = 3, peakVal = 2 * peakRow - 1;
  for ( int i = 1; i <= 2 * peakRow - 1; i++)
  {
     for ( int j = 1; j <= peakVal - 2 * abs( peakRow - i ); j++ ) cout << '*';
     cout << endl;
  }
}
thank you guys, kemort's answer is the best one.
Topic archived. No new replies allowed.