diff --git a/assignments/sauryap/week-1/session-2/problem-1.exe b/assignments/sauryap/week-1/session-2/problem-1.exe new file mode 100644 index 0000000..f2ae884 Binary files /dev/null and b/assignments/sauryap/week-1/session-2/problem-1.exe differ diff --git a/assignments/sauryap/week-1/session-2/problem-1.pdb b/assignments/sauryap/week-1/session-2/problem-1.pdb new file mode 100644 index 0000000..41bf010 Binary files /dev/null and b/assignments/sauryap/week-1/session-2/problem-1.pdb differ diff --git a/assignments/sauryap/week-1/session-2/problem-1.rs b/assignments/sauryap/week-1/session-2/problem-1.rs new file mode 100644 index 0000000..93aa059 --- /dev/null +++ b/assignments/sauryap/week-1/session-2/problem-1.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello World Saurya"); +} \ No newline at end of file diff --git a/assignments/sauryap/week-2/session-1/problem-1.rs b/assignments/sauryap/week-2/session-1/problem-1.rs new file mode 100644 index 0000000..821e0f2 --- /dev/null +++ b/assignments/sauryap/week-2/session-1/problem-1.rs @@ -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); +} diff --git a/assignments/sauryap/week-2/session-1/problem-2.rs b/assignments/sauryap/week-2/session-1/problem-2.rs new file mode 100644 index 0000000..8ff851f --- /dev/null +++ b/assignments/sauryap/week-2/session-1/problem-2.rs @@ -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 + } +} diff --git a/assignments/sauryap/week-2/session-2/problem-1.rs b/assignments/sauryap/week-2/session-2/problem-1.rs new file mode 100644 index 0000000..92732af --- /dev/null +++ b/assignments/sauryap/week-2/session-2/problem-1.rs @@ -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; +} \ No newline at end of file diff --git a/assignments/sauryap/week-2/session-2/problem-2.rs b/assignments/sauryap/week-2/session-2/problem-2.rs new file mode 100644 index 0000000..50f0b38 --- /dev/null +++ b/assignments/sauryap/week-2/session-2/problem-2.rs @@ -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; + +} \ No newline at end of file diff --git a/output.pdb b/output.pdb new file mode 100644 index 0000000..7569901 Binary files /dev/null and b/output.pdb differ