Advertisement
rukvir

HM 2_4

Mar 25th, 2022
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 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 HomeWorck_8_3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Random rand = new Random();
  14.             int number = rand.Next(100);
  15.             int sum = 0;
  16.  
  17.             if (number == 0) {
  18.                 sum = number;
  19.             }
  20.             else
  21.             {
  22.                 for (int counter = 0; counter < number; counter++)
  23.                 {
  24.                     if ((counter % 3) == 0)
  25.                     {
  26.                         sum += counter;
  27.                     }
  28.                     else if ((counter % 5) == 0)
  29.                     {
  30.                         sum += counter;
  31.                     }
  32.                 }
  33.             }
  34.            
  35.             Console.WriteLine(sum);
  36.             Console.ReadKey();
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement