Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prime number calculation
#1
Solved: 10 Years, 8 Months, 3 Weeks ago
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
Reply
#2
Solved: 10 Years, 8 Months, 3 Weeks ago
would you please elaborate your requirement.

Regards,
Sankalp
Reply
#3
Solved: 10 Years, 8 Months, 3 Weeks ago
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
Reply
#4
Solved: 10 Years, 8 Months, 3 Weeks ago
@ 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
Reply
#5
Solved: 10 Years, 8 Months, 3 Weeks ago
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to count a repeated number in number in particular range gollsrin 1 3,412 04-28-2011, 11:41 AM
Last Post: Saket

Forum Jump:


Users browsing this thread: 1 Guest(s)