Advertisement
rukvir

HW 2_4_2

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