Browse Source

Version 0.3

master
Patrick Foubet 1 year ago
parent
commit
7128a0deb0
16 changed files with 104 additions and 0 deletions
  1. +5
    -0
      etape2/ex2_1.rs
  2. +6
    -0
      etape2/ex2_2.rs
  3. +8
    -0
      etape2/ex2_3.rs
  4. +4
    -0
      etape2/ex2_4.rs
  5. +6
    -0
      etape2/ex2_5.rs
  6. +7
    -0
      etape2/ex2_6.rs
  7. +8
    -0
      etape2/ex2_7.rs
  8. +8
    -0
      etape2/ex2_8.rs
  9. +6
    -0
      etape3/ex3_1.rs
  10. +8
    -0
      etape3/ex3_2.rs
  11. +6
    -0
      etape3/ex3_3.rs
  12. +7
    -0
      etape3/ex3_4.rs
  13. +5
    -0
      etape3/ex3_5.rs
  14. +10
    -0
      etape3/ex3_6.rs
  15. +6
    -0
      etape3/ex3_7.rs
  16. +4
    -0
      etape3/ex3_8.rs

+ 5
- 0
etape2/ex2_1.rs View File

@@ -0,0 +1,5 @@
fn main() {
let var = "OK" ;
println! ("La valeur de var est : { }", var);
}


+ 6
- 0
etape2/ex2_2.rs View File

@@ -0,0 +1,6 @@
fn main(){
let var : i32 = 100 ;
let str : String = "Bonne".to_string() ;
println ! ("La valeur de var est : { }", var) ;
println ! ("La valeur de str est : { }", str) ;
}

+ 8
- 0
etape2/ex2_3.rs View File

@@ -0,0 +1,8 @@
fn main(){
let x = 100 ;
let y = 200 ;
let z = 300 ;
println !("{ }", x) ;
print !("{ } { }", y, z) ;
println !(" etc") ;
}

+ 4
- 0
etape2/ex2_4.rs View File

@@ -0,0 +1,4 @@
const NUM : i32 = 100 ;
fn main() {
println ! ("La valeur de NUM est {}", NUM) ;
}

+ 6
- 0
etape2/ex2_5.rs View File

@@ -0,0 +1,6 @@
fn main(){
let var1 : f32 = 100.88 ;
let var2 : i32 = var1 as i32 ; // var1 devient i32
println ! ("{}", var1) ;
println ! ("{}", var2) ;
}

+ 7
- 0
etape2/ex2_6.rs View File

@@ -0,0 +1,7 @@
fn main() {
funt(100, 200) ; // appelle la fonction
}

fn funt(x : i32, y : i32) { // définit une fonction
println ! ("La somme est : { }", x + y) ;
}

+ 8
- 0
etape2/ex2_7.rs View File

@@ -0,0 +1,8 @@
fn main() {
let num = funt(100) ; // appelle la fonction
println ! ("La valeur de num est : { }", num) ;
}

fn funt(num : i32) -> i32 { // spécifier un type de retour
num + 200 // renvoie une valeur à l'appelant
}

+ 8
- 0
etape2/ex2_8.rs View File

@@ -0,0 +1,8 @@
fn foo() -> bool { // spécifier un type de retour
return true // renvoie une valeur à l'appelant
}

fn main() {
let b = foo() ; // foo() est un appelant
println ! ("Le résultat est : { }", b) ;
}

+ 6
- 0
etape3/ex3_1.rs View File

@@ -0,0 +1,6 @@
fn main(){
let (x, y) = (100, 200) ; // liaison de variable
println ! ("La valeur de x est {}", x) ;
println ! ("La valeur de y est {}", y) ;
}


+ 8
- 0
etape3/ex3_2.rs View File

@@ -0,0 +1,8 @@
fn main(){
let mut a = 100 ; // liaison de variable
let mut b = 200 ;
a = a + 300 ;
b = b + 400 ;
println ! ("Finalement, a vaut {}", a) ;
println ! ("Enfin, b vaut {}", b) ;
}

+ 6
- 0
etape3/ex3_3.rs View File

@@ -0,0 +1,6 @@
fn main(){
let x = "hello".to_string() ;
let y = String::from("hello") ;
let z :&str = "hello" ;
print! ("{} {} {}\n", x, y, z) ;
}

+ 7
- 0
etape3/ex3_4.rs View File

@@ -0,0 +1,7 @@
fn main() {
println ! ("10 + 2 = {}", 10 + 2) ;
println ! ("10 - 2 = {}", 10 - 2) ;
println ! ("10 * 2 = {}", 10 * 2) ;
println ! ("10 / 2 = {}", 10 / 2) ;
println ! ("10 % 2 = {}", 10 % 2) ;
}

+ 5
- 0
etape3/ex3_5.rs View File

@@ -0,0 +1,5 @@
fn main() {
println ! ("true AND false is {}", true && false) ;
println ! ("true OR false is {}", true || false) ;
println ! ("NOT true is {}", ! true) ;
}

+ 10
- 0
etape3/ex3_6.rs View File

@@ -0,0 +1,10 @@
fn main() {
let x : i32 = 100 ;
let y : i32 = 200 ;
println ! ("x est plus grand que y : {}", x > y) ;
println ! ("x est inférieur à y : {}", x < y) ;
println ! ("x n'est pas égal à y : {}", x != y) ;
println ! ("x is supérieur ou égal à y : {}", x >= y) ;
println ! ("x est inférieur ou égal à y : {}", x <= y) ;
println ! ("x est strictement égal à y : {}", x == y) ;
}

+ 6
- 0
etape3/ex3_7.rs View File

@@ -0,0 +1,6 @@
fn main() {
let mut a : [i32 ; 4] = [8 ; 4] ; // créer un tableau
a[1] = 10 ;
a[2] = 20 ;
println ! ("{} {} {} {}",a[0], a[1], a[2], a[3]) ;
}

+ 4
- 0
etape3/ex3_8.rs View File

@@ -0,0 +1,4 @@
fn main(){
let a :[f32 ; 4] = [0.1, 0.2, 0.3, 0.4] ; // créer un tableau
println ! ("{} {} {} {}",a[0],a[1],a[2],a[3])
}

Loading…
Cancel
Save