Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create pattern #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

vimalswaroopj
Copy link

No description provided.

@vimalswaroopj
Copy link
Author

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
Copy link
Contributor

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");
}
}

{
let mut s = String::new();
io::stdin().read_line(&mut s).expect("");
let n: i32 = s.parse().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust do not remove whitespace characters automatically when parsing numbers. Please use trim () before calling parse.
s.trim().parse().unwrap()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants