Advertisement
Gudini

Homework2_4

Dec 11th, 2023 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Homework2_4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Random random = new Random();
  14.             int minNumber = 1, maxNumber = 101;
  15.             int number = random.Next(minNumber, maxNumber);
  16.             int firstDivisor = 3, secondDivisor = 5;
  17.             int sum = 0;
  18.  
  19.             Console.WriteLine("Рандомное число: " + number);
  20.  
  21.             for(int i = 1; i <= number; i++)
  22.             {
  23.                 if (i % firstDivisor == 0 || i % secondDivisor == 0)
  24.                 {
  25.                     Console.WriteLine(i);
  26.                     sum += i;
  27.                 }
  28.             }
  29.  
  30.             Console.WriteLine("Сумма всех положительных чисел: " + sum);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement