Skip to content

Instantly share code, notes, and snippets.

@adnanmasood
Created March 21, 2023 14:57
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 adnanmasood/070c423a24947e636aa4ba01eeac3da2 to your computer and use it in GitHub Desktop.
Save adnanmasood/070c423a24947e636aa4ba01eeac3da2 to your computer and use it in GitHub Desktop.
euler_problem1_multiples_of_3_or_5
sum = 0
for i in range(1, 1000):
# Check if i is a multiple of 3 or 5
if i % 3 == 0 or i % 5 == 0:
# Add i to the sum if it's a multiple of 3 or 5
sum += i
print(sum)
fn main() {
let mut sum = 0;
for i in 1..1000 {
// Check if i is a multiple of 3 or 5
if i % 3 == 0 || i % 5 == 0 {
// Add i to the sum if it's a multiple of 3 or 5
sum += i;
}
}
println!("{}", sum);
}
#include <iostream>
int main() {
int sum = 0;
for (int i = 1; i < 1000; i++) {
// Check if i is a multiple of 3 or 5
if (i % 3 == 0 || i % 5 == 0) {
// Add i to the sum if it's a multiple of 3 or 5
sum += i;
}
}
std::cout << sum << std::endl;
return 0;
}
using System;
class Program {
static void Main() {
int sum = 0;
for (int i = 1; i < 1000; i++) {
// Check if i is a multiple of 3 or 5
if (i % 3 == 0 || i % 5 == 0) {
// Add i to the sum if it's a multiple of 3 or 5
sum += i;
}
}
Console.WriteLine(sum);
}
}
open System
let mutable sum = 0
for i in 1 .. 999 do
// Check if i is a multiple of 3 or 5
if i % 3 = 0 || i % 5 = 0 then
// Add i to the sum if it's a multiple of 3 or 5
sum <- sum + i
printfn "%d" sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment