Last active
February 4, 2025 16:15
-
-
Save ALJEMor/59232e955b5aadbe04259780dbadb464 to your computer and use it in GitHub Desktop.
04.02.2025_Работа_с_рандомом
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; | |
namespace Работа_с_рандомом | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
/* С помощью Random получить число number, которое не больше 100. | |
* Найти сумму всех положительных чисел меньше number (включая число), | |
* которые кратные 3 или 5. (К примеру, это числа 3, 5, 6, 9, 10, 12, 15 и т.д.) | |
*/ | |
const int MultipleThree = 3; | |
const int MultipleFive = 5; | |
int maxRange = 101; | |
int multiplicitySum = 0; | |
Random random = new Random(); | |
int number = random.Next(maxRange); | |
Console.WriteLine($"{number}"); | |
for (; number >= 0; number--) | |
{ | |
if (number % MultipleThree == 0 || number % MultipleFive == 0) | |
{ | |
multiplicitySum = multiplicitySum + number; | |
} | |
} | |
Console.WriteLine($"Сумма чисел, кратных {MultipleThree} или {MultipleFive}: {multiplicitySum}."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment