Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Odd and Even Number Puzzle aka FizzBuzz
#2
Solved: 8 Years, 9 Months ago
This is a variation of Fizz Buzz puzzle usually asked in programming interviews.

Here is one of the approach that can be used to solve this question. There can be many ways to arrive at the solution. It will be interesting to see how other QTP forum members approach this question.

  1. Declare a string you wish to make a pattern (in this case "*" )
  2. Take a mod of the given number (in this case since you need to identify an even number use 2)
  3. If mod is 0, print the even number Else use a loop to iterate till n , where "n" is the odd number.
  4. Use another for loop to print the string. first in ascending order and then in descending order.

PHP Code:
Dim strPatterniNumber
strPattern 
"*"
iNumber 3


If iNumber Mod 2 0 Then
    
print iNumber
    
else
    
    For 
1 To iNumber Step 1
        
For 1 To i Step 1 
             
print strPattern
        Next
        
print vbNewLine
    Next    
    
    
For 1 To iNumber Step 1
        
For = (iNumber-1To i Step -
             
print strPattern
        Next
        
print vbNewLine
    Next
    
    
End 
If 
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply


Messages In This Thread
RE: Odd and Even Number Puzzle aka FizzBuzz - by Ankur - 08-09-2015, 10:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find the number of occurrences of each number present in a matrix. Kalai 2 3,377 03-30-2015, 11:28 PM
Last Post: gauravarora6611

Forum Jump:


Users browsing this thread: 1 Guest(s)