Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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