triangle

print triangle and there should be sapce in middle
*
* *
*   *
*     *
* * * * *


While I am kidding around here, I think several members of this forum told you before that we don't give out homework solutions here. It's for your own benefit, believe it or not. :)

What have you tried to get this work so far? We will happily help you after you show at least one reasonable attempt. :/

-Albatross
Last edited on
#include<iostream.h>
#include<conio.h>

main()
{
clrscr();
int n=5;

for (int i=1;i<=n;i++)
{
for (int j=1;j<=n;j++)
{
cout << " ";
}
for (int x=1;x<=i;x++)
{
cout << "*";
cout << " ";
}
cout <<"\n";
n=n-1;
}
getch();
}



it's shows no space in middle
plz give me logic
Alright.

With the exception of the first and last rows, every single row has only two stars: at the beginning of a line, and at the end.

So, what I think you'll want to do is have a for loop to deal with each line (which you have), and inside that, first print one asterisk. Then, in another for loop inside your other for loop, print a number of spaces (from my little picture, do you see how the number of spaces increases?), and outside of that loop print another asterisk and a newline.

Can you try to write that?

-Albatross

P.S: <iostream> should have no .h, main should have an int before it, and you should return 0; at the end of int main().
can you correct it with showing method
progarm run but there is no spaces in middle
Use continue.
compile this:

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
31
32
33
34
35
36
37
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<"                     *"<<endl;
    cout <<"                     * *"<<endl;
    cout <<"                     *   *"<<endl;
    cout <<"                     *     *"<<endl;
    cout <<"                     *       *"<<endl;
    cout <<"                     *         *"<<endl;
    cout <<"                     *           *"<<endl;
    cout <<"                     *             *"<<endl;
    cout <<"                     *               *"<<endl;
    cout <<"                     *                 *"<<endl;
    cout <<"                     * * * * * * * * * * *"<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    cout <<" "<<endl;
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
^ lol
haha looks cool though
Topic archived. No new replies allowed.