Knowee
Questions
Features
Study Tools

WAP to print the prime numbers between 1 – 100

Question

WAP to print the prime numbers between 1 – 100

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Python program that prints all prime numbers between 1 and 100.

# Function to check whether a number is prime or not
def is_prime(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False

    i = 3
    while i * i <= n:
        if n % i == 0:
            return False
        i += 2

    return True

# Loop through the numbers 1 to 100 and print if they are prime
for i in range(1, 101):
    if is_prime(i):
        print(i)

This program works by defining a helper function is_prime(n) that checks whether a given number n is prime. It then loops through the numbers 1 to 100, and for each number, it checks whether it is prime using the is_prime(n) function. If the number is prime, it prints the number.

This problem has been solved

Similar Questions

Write a single line Python code to print all the prime numbers between 1 and 200.

wap in c to find first 20 prime number

# Write a function in python which accept a number from user to return True, if the number#is a prime number else return False. Use this function to print all prime numbers from 1#to 100.

Write a code to print the prime numbers in the given range by using the function isPrime() for the given start and end as range. isPrime() function is predefined, it return 1 if number is prime else it return 0.Input Format:Accept two integers(start and end range) as inputOutput Format:Display the prime numbers as space sepratedConstraints:1 <=  start, end <= 10^6Sample Input 1:29 50Sample Output 1:29 31 37 41 43 47Sample Input 2:1 100Sample Output 2:1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Write a program to print all Armstrong numbers and Prime Numbers in the range inputted by the user. Also print the total count of Prime Numbers in the given range.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.