Monday 13 December 2021

Develop a python program to calculate the square root of (N+1)th Prime number for a given number N using binary search with a precision of upto 7 decimal places

 The python program to calculate the square root of (N+1)th Prime number for a given number N using binary search with a precision of unto 7 decimal places includes the following steps.

1. First we are generating next prime number for a given number

2. Second, we are finding its square root.

3. After we are rounding the values to 7 decimal places

The following program illustrates above process

import math 
def prime(n):
    np=[]
    isprime=[]
    for i in range (n+1,n+200):
        np.append(i)
    for j in np:
        val_is_prime = True
        for x in range(2,j-1):
            if j % x == 0:
                val_is_prime = False
                break
        if val_is_prime:
            isprime.append(j)
    return min(isprime)
n=int(input("Enter a number: "))
x=prime(n)
print("next prime number is",x)

#calculating square root by taking x as input
s=math.sqrt(x)
print("and it squre root is", round(s,7))

The following is the output for above program

Enter a number: 5
next prime number is 7
and it squre root is 2.6457513

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top