Write Sub Vba Figure Given User Supplied Integer N Many Prime Numbers Within 1 N List Shee Q37104666

Write a sub (In VBA) that can figure out, given a user-suppliedinteger n, how many prime numbers are there within 1 and n and willlist them on a sheet in an EXCEL workbook


Solution


Below is the solution:

code:

Sub PrimeNumber()
    Dim Num As Single, i As Single ‘declarevariable
    Num = Cells(1, 1) ‘read number fromcell(1,1)
    k = 1 ‘initialize k to 1
    For i = Num To 1 Step -1 ‘loop Num times to1
        If CheckPrime(i) Then’call function o check the prime number
           Cells(k, 2) = “Prime Number is: ” & i ‘print prime number
           k = k + 1 ‘increment k value
       

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.