Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that

image text in transcribed

Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2: ". If the user's input is less than or equal to 2, then print "No prime number is smaller than . ", where is replaced by the number input by the user. If the user inputs a number greater than 2, then print "Prime numbers smaller than : ". Then, on the same line, print out a list of all prime numbers that are smaller than the input. In your list, each prime number must be separated by one space and a newline must be printed immediately after the last number in the list. As part of your program, you must make a function that takes an integer as an argument, returns 1 if the integer is prime, and returns 0 otherwise. You can use the following function prototype: int isPrime(int number); Example input/output pairs (excluding the prompt) are provided below: Input: 6; Output: Prime numbers smaller than 6: 2 3 5 Input: 23; Output: Prime numbers smaller than 23: 2 3 5 7 11 13 17 19 Input: 1; Output: No prime number is smaller than 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

Students also viewed these Databases questions