Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /*using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace met1
- {*/
- class Program
- {
- static void Tombkiiras(int[] p)
- {
- for (int i = 0; i < p.Length; i++)
- {
- Console.Write(p[i] + " ");
- }
- }
- static int Osszeg(int[] q)
- {
- int sum = 0;
- for (int i = 0; i < q.Length; i++)
- {
- sum += q[i];
- }
- return sum;
- }
- static bool Primvizsgalat(int szam)
- {
- for (int i = 2; i < Math.Sqrt(szam); i++)
- {
- if (szam % i == 0)
- return false;
- }
- return true;
- }
- static int Index(int[] r)
- {
- bool paros = false;
- for (int i = 0; i < r.Length; i++)
- {
- if (r[i] % 2==0)
- {
- paros = true;
- return i;
- }
- }
- return -1;
- }
- static void Main(string[] args)
- {
- int[] tomb = new int[20];
- Random r = new Random();
- for (int i = 0; i < tomb.Length; i++)
- {
- tomb[i] = r.Next(1, 101);
- }
- Tombkiiras(tomb);
- Console.WriteLine();
- Console.WriteLine("Összeg: {0}", Osszeg(tomb));
- bool prim = false;
- for (int i = 0; i < tomb.Length; i++)
- {
- if (Primvizsgalat(tomb[i]) == true )
- {
- prim = true;
- }
- }
- Console.WriteLine("Van prímszám?:"+prim);
- if (Index(tomb) == -1)
- Console.WriteLine("Nem paros.");
- else
- Console.WriteLine("Van paros szam: " + Index(tomb));
- Console.ReadLine();
- }
- }
Add Comment
Please, Sign In to add comment