Guest User

Untitled

a guest
Jan 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2.  
  3. /*using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace met1
  8. {*/
  9.     class Program
  10.     {
  11.         static void Tombkiiras(int[] p)
  12.         {
  13.             for (int i = 0; i < p.Length; i++)
  14.             {
  15.                 Console.Write(p[i] + " ");
  16.             }
  17.         }
  18.  
  19.         static int Osszeg(int[] q)
  20.         {
  21.             int sum = 0;
  22.             for (int i = 0; i < q.Length; i++)
  23.             {
  24.                 sum += q[i];
  25.             }
  26.             return sum;
  27.         }
  28.  
  29.         static bool Primvizsgalat(int szam)
  30.         {
  31.             for (int i = 2; i < Math.Sqrt(szam); i++)
  32.             {
  33.                 if (szam % i == 0)
  34.                     return false;
  35.             }
  36.             return true;
  37.         }
  38.  
  39.         static int Index(int[] r)
  40.         {
  41.             bool paros = false;
  42.             for (int i = 0; i < r.Length; i++)
  43.             {
  44.                 if (r[i] % 2==0)
  45.                 {
  46.                     paros = true;
  47.                     return i;
  48.                 }
  49.             }
  50.             return -1;
  51.         }
  52.         static void Main(string[] args)
  53.         {
  54.             int[] tomb = new int[20];
  55.             Random r = new Random();
  56.             for (int i = 0; i < tomb.Length; i++)
  57.             {
  58.                 tomb[i] = r.Next(1, 101);
  59.             }
  60.             Tombkiiras(tomb);
  61.             Console.WriteLine();
  62.             Console.WriteLine("Összeg: {0}", Osszeg(tomb));
  63.             bool prim = false;
  64.             for (int i = 0; i < tomb.Length; i++)
  65.             {
  66.                
  67.                 if (Primvizsgalat(tomb[i]) == true )
  68.                 {
  69.                     prim = true;
  70.                 }
  71.             }
  72.             Console.WriteLine("Van prímszám?:"+prim);
  73.  
  74.             if (Index(tomb) == -1)
  75.                 Console.WriteLine("Nem paros.");
  76.             else
  77.                 Console.WriteLine("Van paros szam: " + Index(tomb));
  78.             Console.ReadLine();
  79.         }
  80.     }
Add Comment
Please, Sign In to add comment