Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 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 zadanie1
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int a, b;
  15.             Console.WriteLine("Podaj a: ");
  16.             a = Convert.ToInt32(Console.ReadLine());
  17.             Console.WriteLine("Podaj b: ");
  18.             b = Convert.ToInt32(Console.ReadLine());
  19.             int suma = 0;
  20.             int suma2 = 0;
  21.             int mnozenie = 0;
  22.  
  23.         Parallel.Invoke(
  24.                 () =>        
  25.                 {
  26.                     for(int i = a; i <= b; i++)
  27.                     {
  28.                         if (i % 3 == 0)
  29.                         {
  30.                             suma += i;
  31.                         }
  32.                     }
  33.                 },
  34.                 () =>        
  35.                 {
  36.                     mnozenie = a * b;
  37.                     string zmienna = mnozenie.ToString();
  38.                     for (int i = 0; i<zmienna.Length; i++)
  39.                     {
  40.                         suma2 += Convert.ToInt32(zmienna[i].ToString());
  41.                     }
  42.                    
  43.                 }
  44.             );
  45.             Console.WriteLine("suma liczb w przedziale podzielnych przez 3 wynosi: {0}", suma);
  46.             Console.WriteLine("mnozenie: {0}", mnozenie);
  47.             Console.WriteLine("Suma cyfr: {0}", suma2);
  48.             Console.ReadKey();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement