Prime Number Program in Given Range in Python

  

         Prime Number Program in Given Range in Python

Prime number in C: Prime number is a number that is greater than 1 and divided by 1 or itself. In other words, prime numbers can't be divided by other numbers than itself or 1. For example 2, 3, 5, 7, 11, 13, 17, 19, 23.... are the prime numbers.


Program:

a = int(input("Enter Start Value")) 
b = int(input("Enter Ending Value")) 
for i in range(a, b + 1):
    if (i == 1):
        continue

    flag = 1
    for j in range(2, i // 2 + 1):
        if (i % j == 0):
            flag = 0
            break
    if (flag == 1):
        print(i, end = " ")


OutPut:
Enter Start Value1
Enter Ending Value10
2 3 5 7 

Enter Start Value1
Enter Ending Value20
2 3 5 7 11 13 17 19 








No comments:

Post a Comment