Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 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. using System.Threading;
  7.  
  8. namespace Kolokwium
  9. {
  10.     class Program
  11.     {
  12.        
  13.         static void Main(string[] args)
  14.         {
  15.             int x, y;
  16.  
  17.             Console.Write("Podaj pierwszą liczbę");
  18.             int.TryParse(Console.ReadLine(), out x);
  19.  
  20.             Console.Write("Podaj drugą liczbę");
  21.             int.TryParse(Console.ReadLine(), out y);
  22.  
  23.             Parallel.Invoke(
  24.                 () =>
  25.                 {
  26.                     int sum = 0;
  27.  
  28.                     for (int i = x; i < y; i++)
  29.                     {
  30.                         if ( (i % 3) == 0)
  31.                         {
  32.                             sum += i;
  33.                         }
  34.                     }
  35.                     Console.WriteLine("---");
  36.                     Console.WriteLine("Suma liczb z zakresu {0} - {1} podzielnych przez 3 jest równa: {2}", x, y, sum);
  37.                     Console.WriteLine("---");
  38.                 },
  39.                 () =>
  40.                 {
  41.                     int sum = 0;
  42.                     sum = x * y;
  43.  
  44.                     string number = sum.ToString();
  45.                     sum = 0;
  46.  
  47.                     foreach (char c in number)
  48.                     {
  49.                         sum += int.Parse(c.ToString());
  50.                     }
  51.  
  52.                     Console.WriteLine("---");
  53.                     Console.WriteLine("Suma cyfr w liczbie będącej iloczynem liczb: {0} i {1} wynosi: {2}", x, y, sum);
  54.                     Console.WriteLine("---");
  55.                 }
  56.             );
  57.  
  58.             Console.ReadKey();
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement