Last active
April 10, 2025 08:28
-
-
Save Strelok78/239fc2ef139de25d2e80d6a1dee5086c to your computer and use it in GitHub Desktop.
Output sum of numbers up to random number and multiple of 3 or 5
This file contains hidden or 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
namespace iJuniorPractice; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Random random = new Random(); | |
int maxRandomValue = 100; | |
int randomValue = random.Next(maxRandomValue + 1); | |
int multipleFirst = 3; | |
int multipleSecond = 5; | |
int sum = 0; | |
for (int i = 0; i <= randomValue; i++) | |
{ | |
if (i % multipleFirst == 0 || i % multipleSecond == 0) | |
{ | |
sum += i; | |
} | |
} | |
Console.WriteLine($"Randomized number: {randomValue}, sum of numbers multiple of {multipleFirst} " + | |
$"or {multipleSecond}, including the {randomValue} equals {sum}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
random.Next(maxRandomValue); - рандом не возвращает максимум, а значит в рандом надо передавать переменную максимума и делать +1
fixed