Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QTP Tips and Tricks
#31
(07-27-2011, 04:05 PM)rajpes Wrote: Just a puzzle here,You need print the pattern like below depending on no. of rows

rows=3,
**1**
*212*
32123

rows=4,
***1***
**212**
*32123*
4321234


Code:
r=inputbox ("enter no of rows")
c=(2*r)-1
m=(c-1)/2

ReDim a(r-1,c-1)
For i=0 to r-1
    For j=0 to c-1
        a(i,j)="*"
    Next
Next
'mid of all rows
For i=0 to r-1
 a(i,r-1)=1
Next


'rows manipulation
For i=1 to r-1
    For j=0 to m-1
               'If previous row has a value at next column position,increment it by 1
        If a(i-1,j+1)<>"*" Then
            val=a(i-1,j+1)+2 '2 instead of 1 because i am decrementing 'val' by 1 in next line
            For k=j to m-1
                 val=val-1
                 a(i,k)=val
                a(i,c-1-k)=val
            Next
        End If
    Next
Next

'print
For i=0 to r-1
    For j=0 to c-1
      txt= txt& a(i,j)
    Next
    txt=txt&vblf
Next
msgbox txt
If you have a better tested code, please post it


= inputbox("enter no. of rows")
For i = 1 To
 x     
    y = x-
i
    
    
For j = 1 To
 y
        str = str & 
"*"
    
Next
    
    
If i = 1 
Then
        str = str &
 i
    
Else
        For k = i To 1 step 
-1
            str = str &
 k
        
Next
        
        
For k = 2 To
 i
            str = str &
 k
        
Next
        
    
End 
If
    
    
For j = 1 To
 y
        str = str & 
"*"
    
Next
    
    print str

    str 
= 
""
    
Next
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)