Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

i want to get EXEC Pattern 10
ie.,

Output:

1
1 0 1
1 0 1 0 1
1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1
1 0 1 0 1
1 0 1
1



i written the following code

SQL
declare

@x int,@y int

select

@x=10,@y=0

while

@x>0

begin

print

space(@x)+replicate('1',@y)+replicate('1',@y+1)

set

@y=@y+1

set

@x=@x-1

end

select

@x=0,@y=9

while

@y>0

begin

print

space(@x+2)+replicate('1',@y)+replicate('1',@y-1)

set

@y=@y-1

set

@x=@x+1

end


output as:

1
111
11111
1111111
111111111
11111111111
1111111111111
111111111111111
11111111111111111
1111111111111111111
11111111111111111
111111111111111
1111111111111
11111111111
111111111
1111111
11111
111
1
Posted
Updated 30-Oct-13 17:24pm
v3
Comments
chaau 30-Oct-13 22:54pm    
BTW, your print space(@x)+replicate('1',@y)+replicate('1',@y+1) will produce the pattern like < sign (e.g. left-padded with spaces). Is this what you want? If yes, then modify the statement to this:
print space(@x)+'1 '+replicate('0 1', @y)
chaau 30-Oct-13 22:56pm    
Just wanted to add: if you want it in > sign pattern (like in your question) then use
print '1 '+replicate('0 1', @y)

(Basically, you do not need @x)
Sergey Alexandrovich Kryukov 30-Oct-13 22:58pm    
Your teachers don't have any fantasy, they all give the very similar assignments. This is homework, isn't it?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900