rustindia / Rust-for-undergrads

C/C++ programming probelms re-written in Rust
https://rustindia.github.io/Rust-for-undergrads/
GNU General Public License v3.0
249 stars 113 forks source link

Create pattern #75

Open vimalswaroopj opened 5 years ago

vimalswaroopj commented 5 years ago

use std::io; fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).expect(""); let n: i32 = s.parse().unwrap(); let mut x: i32; x=n; let mut y: i32; y=1; for i in 0..n {

    for j in 0..(x)
    {
        print!(" ")
    }
    for k in 0..y
    {
        print!("*");
    }
    y=y+2;
    x=x-1;
    print!("\n");
}
x=0;
for i in 0..n+1
{
    for j in 0..(x)
    {
        print!(" ")
    }
    for k in 0..y
    {
        print!("*");
    }
    y=y-2;
    x=x+1;
    print!("\n");
}

}

Sameer184 commented 5 years ago

use std::io; fn read()->i32 { let mut num=String::new(); io::stdin() .read_line(&mut num) .expect("Error"); num.trim() .parse::() .unwrap() }

fn main() { println!("Enter n"); let n = read(); // let size = read() as usize; for i in 0..n { for j in 0..i { print!("*"); } println!("\n"); } }