Question: Write an F# program that asks the user to input an integer, then decides if that integer is prime and prints a message accordingly. To

 Write an F# program that asks the user to input an

Write an F# program that asks the user to input an integer, then decides if that integer is prime and prints a message accordingly. To determine if x is prime, see if any of the integers 2, 3, 4, ... are divisors of x; if they are, x is not prime. You will need to use mutable variables for this task, along with a while loop and if statement(s). Please review the Intro.fs file for syntax. To read an input, start your program like this: open System let x = Console.ReadLine() /> int We'll learn the (> syntax later. This is equivalent to int(input()) in Python, scanner.nextInt() in Java, etc. Your implementation must be correct and efficient. In particular: = . . You must stop looping the moment you know the integer is not prime. You must not test x to see if 4, 6, 8, 10, ... are divisors. If 2 is not a divisor, then no even integer will be a divisor. You must stop the loop once you have exceeded the largest integer that could be a divisor of x, which is the sqrt of x. You must do division, modulo, etc. using int data types, not float. At some point you will be tempted to make x a float. Don't do it. Use casting operators like (float x) if you are getting errors about comparing two different variable types

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!