Skip to content

Instantly share code, notes, and snippets.

@ttsugriy
Created June 12, 2021 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttsugriy/cede61a2dcca263f4b4c7a6b61474112 to your computer and use it in GitHub Desktop.
Save ttsugriy/cede61a2dcca263f4b4c7a6b61474112 to your computer and use it in GitHub Desktop.
Sum of N, Rust version
#[no_mangle]
pub fn sum_of_n_unsigned(n: usize) -> usize {
let mut total = 0;
for i in 1..=n {
total += i;
}
total
}
#[no_mangle]
pub fn sum_of_n_signed(n: i32) -> i32 {
let mut total = 0;
for i in 1..=n {
total += i;
}
total
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment