2. About Numbers You need to make a program that: • asks a user to type in a positive number greater than 0, • checks if the number provided really is greater than 0, less than 0 (invaldi), or equal to 0 (stop program), • runs some tests on that number and reports results to the user • repeats the entire process until the user types in a 0. What tests? In your last lab you provided the reciprocal and log₂ values for the user supplied number. This week you'll do some additional tests: • reports whether the number is even or odd • reports whether the number is a multiple of 3 or not • reports wehther the number is prime or not

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

bool isprime(long n) /* fixed from to https://www.geeksforgeeks.org/euclid-euler-theorem/?ref=lbp */
{
    // check whether a number is prime or not
    int i;
    for (i = 2; i * i <= n; i++)
        if (n % i == 0)
            return false;
    return true;
}

2. About Numbers
You need to make a program that:
• asks a user to type in a positive number greater than 0,
• checks if the number provided really is greater than 0, less than 0 (invaldi), or equal to 0 (stop
program),
• runs some tests on that number and reports results to the user
repeats the entire process until the user types in a 0.
What tests? In your last lab you provided the reciprocal and log2 values for the user supplied number. This
week you'll do some additional tests:
reports whether the number is even or odd
reports whether the number is a multiple of 3 or not
reports wehther the number is prime or not
A sample run of the program might look like:
Enter a number greater than 0: 5
Number 5 is odd is not multiple of 3 is prime
Enter a number greater than 0: 6
Number 6 is even is multiple of 3 is not prime
Enter a number greater than 0: -4
Bogus: number must be > 0
Enter a number greater than 0: 253
Number 253 is odd is not multiple of 3 is not prime
Enter a number greater than 0:0
Bye.
The code to determine if a number is prime or not will be provided on NUoodle: you can cut and paste it
into your program.
3. Some Tips
A common mistake of novice programs is to think they have to build the entire program before trying it.
Don't try to build the whole program at once: do it in smaller steps that you can test. When one step it working,
add the next one.
For example, start with just the code that asks the user for input, reads in the number, then prints it out
to the user. You've already done that in Lab 2, so you could use the same code for that here. Compile and
test that.
When that works, add the code to make the loop: keep asking the user for a number until they type in 0,
then stop (use the break instruction). You could also add the code testing for a value < 0 and printing
error message (and using the continue instruction. Compile and test that.
When that works, add code for tests of the value; try just the even/odd first. Compile and test that.
And so on, adding small bits at a time to code you know already works.
Transcribed Image Text:2. About Numbers You need to make a program that: • asks a user to type in a positive number greater than 0, • checks if the number provided really is greater than 0, less than 0 (invaldi), or equal to 0 (stop program), • runs some tests on that number and reports results to the user repeats the entire process until the user types in a 0. What tests? In your last lab you provided the reciprocal and log2 values for the user supplied number. This week you'll do some additional tests: reports whether the number is even or odd reports whether the number is a multiple of 3 or not reports wehther the number is prime or not A sample run of the program might look like: Enter a number greater than 0: 5 Number 5 is odd is not multiple of 3 is prime Enter a number greater than 0: 6 Number 6 is even is multiple of 3 is not prime Enter a number greater than 0: -4 Bogus: number must be > 0 Enter a number greater than 0: 253 Number 253 is odd is not multiple of 3 is not prime Enter a number greater than 0:0 Bye. The code to determine if a number is prime or not will be provided on NUoodle: you can cut and paste it into your program. 3. Some Tips A common mistake of novice programs is to think they have to build the entire program before trying it. Don't try to build the whole program at once: do it in smaller steps that you can test. When one step it working, add the next one. For example, start with just the code that asks the user for input, reads in the number, then prints it out to the user. You've already done that in Lab 2, so you could use the same code for that here. Compile and test that. When that works, add the code to make the loop: keep asking the user for a number until they type in 0, then stop (use the break instruction). You could also add the code testing for a value < 0 and printing error message (and using the continue instruction. Compile and test that. When that works, add code for tests of the value; try just the even/odd first. Compile and test that. And so on, adding small bits at a time to code you know already works.
Expert Solution
Step 1

Program to check if a number is even or odd, is a multiple of 3 or not, is prime or not.

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education