o4-mini-2025-04-16· OpenAI
LMArena Human Preference 140K
Write a Rust program that sums all elements of an array of 10 integers.
- User
Write a Rust program that sums all elements of an array of 10 integers.
- Assistant
Here’s a simple Rust program that defines a fixed array of 10 integers and computes their sum in two ways:
- With a
for-loop - With the built-in iterator method
iter().sum()
fn main() { // 1) Define your array of 10 integers let arr: [i32; 10] = [5, 3, 8, 1, 6, 9, 2, 7, 4, 10]; // Method A: use a for-loop let mut sum_loop = 0; for &value in &arr { sum_loop += value; } println!("Sum computed by loop: {}", sum_loop); // Method B: use Iterator::sum() let sum_iter: i32 = arr.iter().sum(); println!("Sum computed by iter().sum(): {}", sum_iter); } - With a
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.