drawing shapes

Dec 13, 2014 at 9:18pm

how can I get the following result





1 2 3 4 5 6 7 6 5 4 3 2 1
1 2 3 4 5 6 * 6 5 4 3 2 1
1 2 3 4 5 * * * 5 4 3 2 1
1 2 3 4 * * * * * 4 3 2 1
1 2 3 * * * * * * * 3 2 1
1 2 * * * * * * * * * 2 1
1 * * * * * * * * * * * 1

code]
#include <iostream>

int main ()
{
for(int i=0;i<=12; i++)

?
?
?
}
[/code]
Dec 13, 2014 at 9:56pm
You're going to need two for loops.
Dec 13, 2014 at 10:39pm

but how can I use....
kindly help I am got confused..
I am a beginner...
Dec 13, 2014 at 10:43pm
Look at the pattern. You iterate up, then you iterate down and repeat until you run out of numbers. Alternatively you can have a string and modify it. Though that wouldn't be as modular in design.
Last edited on Dec 13, 2014 at 10:45pm
Dec 13, 2014 at 11:04pm
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
for(int h = 7;h<=0;h++){
for(int i=0;i<=7;i++){

for(int k=i;k<0;k+=2){
cout<<"*"; 
}
for(int j=6;j>0;j--)
}
}


My compiler is not working kindly compile it and tell me if it is working or not.
thanka in advance.....
Dec 13, 2014 at 11:12pm
It's not your compiler not working. The code does not make sense and has several syntax errors.

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

using namespace std;
int main()
{
    for(int h = 7;h<=0;h++)
    {
        for(int i=0;i<=7;i++)
        {
            for(int k=i;k<0;k+=2)
            {
                cout<<"*"; 
            }
        for(int j=6;j>0;j--)
        }
Last edited on Dec 13, 2014 at 11:12pm
Dec 14, 2014 at 6:18am
work for the stars
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
#include <iostream>
using namespace std;

int main()
{
	int height = 7;	
	
    for(int r =1, s=0 ; r<=height; r++, s++)
    {
    	bool b = false;
    	
        for(int i=1; i<=height ; i++)
        {	
        	if(i<=height) cout << i << " "; 
        	if(i==height) 
        	{
        		for(int j=height-1; j>=1 ; j--)
        		{
        			cout << j << " ";
        		}
        	}
        }
        cout << endl;
	}
	
return 0;	
}


if still too hard,
try left sided stars first

*
**
***
****
Topic archived. No new replies allowed.