Create a Rust program to determine if a number is prime or not.
Create a Rust program to determine if a number is prime or not.
408
20-Jun-2023
Aryan Kumar
24-Jun-2023Sure, here is a Rust program to determine if a number is prime or not:
Rust
This program first checks if the number is less than 2. If it is, then the program returns false. Otherwise, the program iterates over all numbers from 2 to the square root of the number. For each number in the loop, the program checks if the number is divisible by the current number. If the number is divisible by the current number, then the program returns false. Finally, the program returns true if the number is not divisible by any of the numbers.
To run this program, you can save it as a
.rsfile and then compile and run it using the following commands:Code snippet
This will prompt you to enter a number. Enter a number and press Enter. The program will then print whether the number is prime or not.