daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn main() {
  2.     // $s0
  3.     let mut n: i32 = 0;
  4.    
  5.     // $s1
  6.     let mut sum: i32 = 0;
  7.    
  8.     // $s2
  9.     let mut min: i32 = 0;
  10.    
  11.     // $s3
  12.     let mut max: i32 = 0;
  13.    
  14.     // $f2
  15.     let mut sq_sum: f32 = 0.0;
  16.    
  17.  
  18. // loop:
  19.     for input in 1..=9 { // taking in "input"
  20.         println!("{}", input);
  21.        
  22.         if input < 0 {
  23.             break;
  24.         }
  25.        
  26.         n += 1;
  27.        
  28.         if n == 1 {
  29.             min = input;
  30.             max = input;
  31.         }
  32.  
  33.         sum += input;
  34.  
  35.         if input < min {
  36.             min = input;
  37.         }
  38. // c1:
  39.  
  40.         if input > max {
  41.             max = input;
  42.         }
  43. // c2:
  44.  
  45.         // $f2
  46.         let mut input_f = input as f32;
  47.         input_f = input_f * input_f;
  48.        
  49.         sq_sum = sq_sum + input_f;
  50.     }
  51.    
  52.    
  53. // results:
  54.  
  55.     // $f2
  56.     let sum_f = sum as f32;
  57.    
  58.     // $f3
  59.     let n_f = n as f32;
  60.    
  61.     // $f4
  62.     let mean = sum_f / n_f;
  63.    
  64.     // $f5
  65.     let mut v_temp = sum_f * sum_f;
  66.     v_temp = v_temp / n_f;
  67.    
  68.     // $f6
  69.     let mut variance = sq_sum - v_temp;
  70.     variance = variance / n_f;
  71.  
  72.     println!("     sum: {}", sum);
  73.     println!("     min: {}", min);
  74.     println!("     max: {}", max);
  75.     println!("    mean: {}", mean);
  76.     println!("variance: {}", variance);
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top