Created
March 20, 2022 13:56
-
-
Save erikg/17d2815440096008831633297d08272b to your computer and use it in GitHub Desktop.
minimal program to sum values from stdin, in rust.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{io, io::prelude::*}; | |
pub fn main() { | |
let mut sum = 0; | |
for line in io::stdin().lock().lines() { | |
sum = sum + line.unwrap().parse::<i32>().unwrap(); | |
} | |
println!("{}", sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awk
BEGIN{SUM=0}{SUM+=$1}END{print SUM}