Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active May 16, 2023 15:57
Show Gist options
  • Save Strelok78/8a73040e896ca0d992e7c37e9c84bb30 to your computer and use it in GitHub Desktop.
Save Strelok78/8a73040e896ca0d992e7c37e9c84bb30 to your computer and use it in GitHub Desktop.
Using Random to get a number that is less equal than 100. Finding the sum of all positive numbers less than numbers that are multiples of 3 or 5.
namespace MyCode
{
internal class Program
{
static void Main(string[] args)
{
int minValue = 0;
int maxValue = 100;
int divider1 = 3;
int divider2 = 5;
int number = new Random().Next(minValue, maxValue);
int sum = 0;
for (int i = 0; i <= randomValue; i++)
{
if (i % divider1 == 0 || i % divider2 == 0)
{
sum += i;
}
}
Console.WriteLine(sum);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment