usestd::io::{self,Write};fnmain(){constPI:f32=3.14;letmutinput=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(&mutinput).unwrap();letr: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
codeaft@codeaft:~$ rustc codeaft.rs codeaft@codeaft:~$ ./codeaft
———————————————————————————————————————————
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
———————————————————————————————————————————
codeaft@codeaft:~$
Comments and Reactions
Thank You
Dear User, Thank you for visitng Codeaft. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.