Skip to content

Commit a5f0a5b

Browse files
committed
gcd
1 parent 0b4b76a commit a5f0a5b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

rexdy/euclids_algo.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::io;
2+
3+
fn gcd(mut a:i32, mut b:i32)->i32{
4+
while b!=0{
5+
let r:i32 = a%b;
6+
a=b;
7+
b=r;
8+
}
9+
return a;
10+
}
11+
12+
fn main(){
13+
let a:i32;
14+
let b:i32;
15+
let mut buffer:String = String::new();
16+
println!("Enter first number:");
17+
io::stdin().read_line(&mut buffer).expect("failed to reed user input");
18+
a = match buffer.trim().parse(){
19+
Ok(num) => num,
20+
Err(_) => {
21+
println!("Error parsing string");
22+
return;
23+
}
24+
};
25+
buffer = String::new();
26+
println!("Enter second number:");
27+
io::stdin().read_line(&mut buffer).expect("failed to reed user input");
28+
b = match buffer.trim().parse(){
29+
Ok(num) => num,
30+
Err(_) => {
31+
println!("Error parsing string");
32+
return;
33+
}
34+
};
35+
let ans = gcd(a,b);
36+
println!("GCD(a,b)={}",ans);
37+
}

rexdy/rexdy-code

Whitespace-only changes.

0 commit comments

Comments
 (0)