Rust program to accept the input from a user
kw.rs
use std::io::{self, Write};
fn main()
{
    const PI:f32=3.14;
    let mut input=String::new();
    
    println!("———————————————————————————————————————————");
    println!("Program to calculate the area and circumference of a circle");
    println!("———————————————————————————————————————————");
    print!("Enter the radius of a circle ");
    io::stdout().flush().ok();
    io::stdin().read_line(&mut input).unwrap();
    let r:f32=input.trim().parse().unwrap();
    println!("The area of a circle is {a}",a=PI*r*r);
    println!("The circumference of a circle is {c}",c=2.0*PI*r);
    println!("———————————————————————————————————————————");
}
Output
kodingwindow@kw:~$ rustc kw.rs
kodingwindow@kw:~$ ./kw ——————————————————————————————————————————— Program to calculate the area and circumference of a circle ——————————————————————————————————————————— Enter the radius of a circle 5 The area of a circle is 78.5 The circumference of a circle is 31.400002 ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement