File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments