How to make the following pattern | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

How to make the following pattern

* ** *** **** *****

26th Aug 2017, 2:34 AM
Nabarup Ghosh
Nabarup Ghosh - avatar
5 Answers
+ 4
#include <iostream> using namespace std; int main() { int i, j, k, n; cout << "Enter the number of star lines: "; cin >> n; cout << endl; for(i = 0; i < n; ++i) { for(j = 0; j < (n-i-1); ++j) { cout << " "; } for(k = 0; k < (2 * i + 1); ++k) { cout << "*"; } cout << endl; } return 0; }
26th Aug 2017, 3:05 AM
ChaoticDawg
ChaoticDawg - avatar
+ 4
visit Hebron.Amjadcloud.com its full of simular codes In c++ they would be a great benefit in expanding your concept
2nd Sep 2017, 7:42 AM
F.Heeh. 2nd Yr. Hebron University‏‎
F.Heeh. 2nd Yr. Hebron University‏‎ - avatar
+ 4
ah. it's better to define the counters I,.... In the loop not in the start of the code
2nd Sep 2017, 7:44 AM
F.Heeh. 2nd Yr. Hebron University‏‎
F.Heeh. 2nd Yr. Hebron University‏‎ - avatar
+ 1
#include <iostream> #include <conio.h> void 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";     } }
2nd Sep 2017, 1:15 PM
Ehson
0
#include <iostream> using namespace std; void main() { for (int i = 1; i<=5 ; i++) { for( int j = 1 ; j <= i ; j++) { cout <<"*"; cou << "\n"; } } }
7th Sep 2017, 12:34 PM
AbdelRahman Hassan
AbdelRahman Hassan - avatar