Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active April 10, 2025 08:28
Show Gist options
  • Save Strelok78/239fc2ef139de25d2e80d6a1dee5086c to your computer and use it in GitHub Desktop.
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
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}");
}
}
@Strelok78
Copy link
Author

random.Next(maxRandomValue); - рандом не возвращает максимум, а значит в рандом надо передавать переменную максимума и делать +1
fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment