Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please use comments for each code block and read the hints. Question 1 of 2. Test for Primes: [50 marks] Write a C++ program which
Please use comments for each code block and read the hints.
Question 1 of 2. Test for Primes: [50 marks] Write a C++ program which will ask the user to input an integer number and test if it is a prime number A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. Some prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, ... Make sure your code works for any input number, not just the test cases. Your code will be tested on other test cases not listed here. Please properly comment your code before submission. Sample Test cases: Test case 1: Input: Enter the first number: 8 Test case 2: Input: Enter the first number: 29 Output: Prime ?: False Output: Prime ?: True Test case 3: Input: Enter the first number: 100 Test case 4: Input: Enter the first number: 97 Output: Prime ?: False Output: Prime ?: True HINTS: Think about the problem before you start coding. We need to test if the input integer is divisible by any number up to the input integer. We need to use loops, and test divisibility for all the numbers up to the input
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started