Skip to content

Commit

Permalink
Assignment iBrizAcademy#1
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurya P committed Dec 22, 2021
1 parent 520401e commit 4057a0c
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions assignments/sauryap/week-1/session-2/problem-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello World Saurya");
}
41 changes: 41 additions & 0 deletions assignments/sauryap/week-2/session-1/problem-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
fn main() {

let mut arr: [i32; 5] = [5, 6, 3, 1, 10];
let mut j =0;

println!("Before {:?}", arr);
loop {

if arr[j] > arr[j+1]
{
bubbleswap(&mut arr);
j =0;

}else{
j = j+1;
}

if j >=4 {
println!("After {:?}", arr);
break;
}
}


}

fn bubbleswap(arr:&mut [i32; 5]) {
let mut x = 0;
for i in 0..arr.len()-1{

if arr[i] > arr[i+1]
{
println!("{} is great than {}", arr[i], arr[i+1]);
x = arr[i];
arr[i] = arr[i+1];
arr[i+1] = x;
}
}

// println!("{:?}", arr);
}
34 changes: 34 additions & 0 deletions assignments/sauryap/week-2/session-1/problem-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
fn main() {
let word1:&str = "helodi";
let word2:&str = "olehdi";

println!("The strings {} and {} are {} anagrams", word1, word2, checkanagram(word1, word2));
}

fn checkanagram(word1:&str, word2:&str) -> bool {
let mut c = 0;

if word1.len() > word2.len() {
return false
}else {
for i in word1.chars(){
for j in word2.chars(){


if i == j {

c = c+1;
}
}

}
}



if c == word1.len(){
return true
}else {
return false
}
}
26 changes: 26 additions & 0 deletions assignments/sauryap/week-2/session-2/problem-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Program to pass ownership of a struct object, to a method and then returning it.

#[derive(Debug)]
struct Company {
name: String,
ceo: String,
age: i32
}

fn main() {

let c1 = Company {
name: String::from("XYZ"),
ceo: String::from("Xi Ping"),
age: 40
};

let c2 = ownershiptransfer(c1);
println!("{:?}", c2);

}

fn ownershiptransfer(c3:Company) -> Company {
println!("Function call - Ownership Transfer");
return c3;
}
28 changes: 28 additions & 0 deletions assignments/sauryap/week-2/session-2/problem-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Program to pass struct variable as reference and dereferencing to modify value of object

#[derive(Debug)]
struct Company {
name: String,
ceo: String,
age: i32
}

fn main() {

let mut c1 = Company {
name: String::from("XYZ"),
ceo: String::from("Xi Ping"),
age: 40
};
println!("Before Referencing {:?}", c1);

ownershiptransfer(&mut c1);
println!("After Referencing {:?}", c1);

}

fn ownershiptransfer(c1:&mut Company) {
(*c1).name = String::from("ABC");
(*c1).age = 30;

}
Binary file added output.pdb
Binary file not shown.

0 comments on commit 4057a0c

Please sign in to comment.