Micro Focus QTP (UFT) Forums
Prime number calculation - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Prime number calculation (/Thread-Prime-number-calculation)



Prime number calculation - aditya2304 - 12-07-2011

Can anyone write the VB script code for QTP for the following problem -

Declare an array of size 4, increase its side to 7 and then find out which of the elements are prime numbers using functions


RE: Prime number calculation - sshukla12 - 12-07-2011

would you please elaborate your requirement.

Regards,
Sankalp


RE: Prime number calculation - ravi.gajul - 12-07-2011

Try this
Code:
Dim arr()
ReDim arr(4)
arr(0)=1
arr(1)=1
arr(2)=2
arr(3)=3
arr(4)=4
ReDim Preserve arr(7)
arr(5)=5
arr(6)=6
arr(7)=7
For i=0  to ubound(arr)
    For j=2 to ubound(arr)
        If arr(i)  mod j=0 Then
           If  arr(i) = j Then
                msgbox "Prime" & arr(i)
            
             Else
            msgbox "Not Prime" & arr(i)
            
            Exit for
                            End If
          End If
           Next
Next



RE: Prime number calculation - aditya2304 - 12-13-2011

@ Ravi gajul
Thanks a lot ravi for ur solution ... this wil work fine but u haven't used functions...i want the same program to be coded using functions
@sankalp

I think the requirements are very clear..
A program needs to be coded using functions which have 7 elements(after increasing array size from 4 to 7) and then to find out which of the elements are prime out of the 7 elements.

If program is coded in such a manner that using functions it can find out all the prime numbers present in an array,,, then i think we can get a perfect program

Awaiting ur reply


RE: Prime number calculation - ravi.gajul - 12-13-2011

Use the same code starting from for loop in the function and pass array(by ref) as the argument to the function.I thought you will do that.