subject

I am writing a code that requires me to identify a positive integer as a prime (or not). I have looked at references on how to find it but it does not work for what I am trying to do. Below is the set of instructions. I have written the first half of the code and verified that it works. I am stuck on how to write the logic that identifies the prime based on the instructions.
Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number.
Your program should use a loop to validate the positive integer and accept the input only when the user inputs a positive number.
Your code should be an efficient algorithm using the following note.
(Note: An even number is prime if it is 2. An odd integer is prime if it is not divisible by any odd integer less than or equal to the square root of the number.)
For the square root, import the math library (import math) and use math. sqrt() function)

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 12:00
The following function returns a string of length n whose characters are all 'x'. give the order of growth (as a function of n) of the running time. recall that concatenating two strings in java takes time proportional to the sum of their lengths. public static string f(int n) { if (n == 0) return ""; if (n == 1) return "x"; return f(n/2) + f(n - n/2); } options: a) constant b) logarithmic c) linear d) linearithmic e)quadratic f)cubic g) exponential
Answers: 2
question
Computers and Technology, 22.06.2019 19:20
Amedian in the road will be marked with a white sign that has a black arrow going to the left of the median. true false
Answers: 1
question
Computers and Technology, 22.06.2019 21:30
Write a function named printfloatrepresentation(float number) that will print the floating point representation of a number using the format given below. (sign bit) exponent in binary (assumed bit).significandfor example if the number passed an argument is 71 yourprogram should print (0) 10000101 (1).00011100000000000000000similarly if the number passed to the function as argument is -71 the program should print (1) 10000101 (1).00011100000000000000000
Answers: 3
question
Computers and Technology, 23.06.2019 12:10
2. fabulously fit offers memberships for$35 per month plus a $50 enrollmentfee. the fitness studio offersmemberships for $40 per month plus a$35 enrollment fee. in how many monthswill the fitness clubs cost the same? what will the cost be?
Answers: 1
You know the right answer?
I am writing a code that requires me to identify a positive integer as a prime (or not). I have look...
Questions
question
Mathematics, 06.05.2020 19:14
question
Mathematics, 06.05.2020 19:14
question
Mathematics, 06.05.2020 19:14
question
Mathematics, 06.05.2020 19:14
question
Mathematics, 06.05.2020 19:14
question
Mathematics, 06.05.2020 19:14
question
Mathematics, 06.05.2020 19:14
Questions on the website: 13722359