0

Does anyone know how to write a code which comes out like a list in C++

A code which brings an output like this Line. Asterisk 1. * 2. ** 3. *** 4. **** 5. ***** 6. ****** 7. ***** 8. **** 9. *** 10. ** 11. *

3rd May 2020, 8:35 PM
BENJAMIN NARTEY
18 Antworten
3rd May 2020, 10:09 PM
ycsvenom
ycsvenom - avatar
0
Please help put
3rd May 2020, 8:36 PM
BENJAMIN NARTEY
0
Have you tried to solve the task? Can you show us that attempt?
3rd May 2020, 8:52 PM
HonFu
HonFu - avatar
0
Okay sure
3rd May 2020, 8:59 PM
BENJAMIN NARTEY
0
#include <iostream> Using namespace std; int main() { cout<<"Line"<<endl; for(int x=1;x<=19;x++){ cout<< x <<endl; } int row=0; int nasterisk; for(row=1;row<=10;row++){ nasterisk; cout<<"\t\t"; for(nasterisk=1;nasterisk<=row;nasterisk++){ cout<<"*"; cout<<endl; } for(row=9; row>=0;row--){ cout<<"t\t\"; for(nasterisk=1;nasterisk<=row;nasterisk++) cout<<"*"; cout<<endl; } } system("pause"); return 0; }
3rd May 2020, 9:23 PM
BENJAMIN NARTEY
0
This is the code
3rd May 2020, 9:23 PM
BENJAMIN NARTEY
0
There is some bugs and the code is too long
3rd May 2020, 9:30 PM
ycsvenom
ycsvenom - avatar
0
Some bugs like?
3rd May 2020, 9:33 PM
BENJAMIN NARTEY
0
Try to put in the code
3rd May 2020, 9:34 PM
ycsvenom
ycsvenom - avatar
0
How? I don't understand
3rd May 2020, 9:38 PM
BENJAMIN NARTEY
0
#include <iostream> #include<iomanip> using namespace std; int main() { int line; cin>>line; for(int i=0;i<line;i++){ cout<<left<<setw(4)<<i+1; for(int j=0;j<=(i<=line/2? i:line-i-1);j++){ cout<<"*"; } cout<<endl; } return 0; }
3rd May 2020, 9:51 PM
ycsvenom
ycsvenom - avatar
0
That's would work
3rd May 2020, 9:51 PM
ycsvenom
ycsvenom - avatar
0
Because you cout line before asterisk not with it That's first
3rd May 2020, 9:52 PM
ycsvenom
ycsvenom - avatar
0
Mohamed ELomari did you see line number 11 and 12 in output of your code?
3rd May 2020, 10:14 PM
ycsvenom
ycsvenom - avatar
0
No
3rd May 2020, 10:39 PM
BENJAMIN NARTEY
0
Thanks it worked out
3rd May 2020, 10:51 PM
BENJAMIN NARTEY
0
#include <iostream> using namespace std; int d; int main() { for(int i=-4;i<=4;i++){ d=5-abs(i); for(int j=0;j<d;j++) cout<<"*"; //use printf("*"); cout<<endl;}//use printf("/n"); return 0; }// abs function is return positive value
5th May 2020, 6:13 PM
Noman
Noman - avatar