Created
March 21, 2023 14:57
-
-
Save adnanmasood/070c423a24947e636aa4ba01eeac3da2 to your computer and use it in GitHub Desktop.
euler_problem1_multiples_of_3_or_5
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
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) |
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
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); | |
} |
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
#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; | |
} |
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
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); | |
} | |
} |
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
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