Prime Number in Rust

Published on 28 April 2022 (Updated: 25 September 2022)

Prime Number in Rust

Welcome to the Prime Number in Rust page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

//  Requirement
// Accept a number on command line and print if it is Composite or Prime 
// Works till  39 digits, ...

use std::process;
fn main() {
    //confirm integer is passed as commandline argument
    let mut input_value = std::env::args().nth(1).expect("please input a non-negative integer");
    // Trim the trailing newline
    input_value = input_value.trim_end().to_string();
    //String to Int
    let input_num: u128 = input_value
        .expect("please input a non-negative integer");

    let mut n = 3 as u128;
    let divisor = input_num /2 as u128;

    if input_num % 2 == 0 {
    while n < divisor {  
        if input_num % n == 0 {
        n = n + 2;
    if n >= divisor {

Prime Number in Rust was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.