Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Library named assignment
- pub mod read_input {
- use::std::io;
- pub fn read()-> String {
- let mut input = String::new();
- io::stdin().read_line(&mut input);
- input.to_string()
- }
- }
- pub fn area_circle (f:f32) -> (f32) {
- let pi:f32= (22.0/7.0);
- let sq:f32 = f * f;
- let ar:f32=sq*pi;
- ar as f32
- }
- pub fn pos_neg (c:i32)-> String {
- if c == 0 {
- println!("Entered Zero \n");
- } else if c>=0{
- println!("Entered Positive Number \n");
- }
- else if c <= 0 {
- println!("Entered Negative Number \n");
- }c.to_string()
- }
- pub fn vol_sphere (g:f32) -> (f32) {
- let pi:f32= (22.0/7.0);
- let cub:f32 = g * g * g;
- let vol:f32=(4.0*cub*pi)/3.0;
- vol as f32
- }
- // package code
- extern crate assignment;
- fn main() {
- //Challenge1
- println!("Challenge1");
- println!("Enter Radius of Circle");
- let mut c1= assignment::read_input::read();
- let c1= c1.trim().parse().unwrap();
- let c1_1=assignment::area_circle(c1);
- println!("Area of circle for given Radius is {} \n", c1_1);
- //Challenge2
- println!("Challenge2");
- println!("Enter Number");
- let mut c2= assignment::read_input::read();
- let c2= c2.trim().parse().unwrap();
- assignment::pos_neg(c2);
- //Challenge4
- println!("Challenge4");
- println!("Enter Radius of Sphere");
- let mut c4= assignment::read_input::read();
- let c4= c4.trim().parse().unwrap();
- let c4_1=assignment::vol_sphere(c4);
- println!("Area of circle for given Radius is {} \n", c4_1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement