Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Repeat Problem 939E using argon as the working fluid.

Answered: 1 week ago

Question

Which personal relationships influenced you the most?

Answered: 1 week ago