Advertisement
GraionDilach

Számkeresés alfüggvénnyel tömbből

Nov 14th, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication11
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Random RandNum = new Random();
  13.  
  14.             int[] array = new int[10];
  15.  
  16.             for (int i = 0; i < array.Length; i++)
  17.             {
  18.                 array[i] = RandNum.Next(100);
  19.                 Console.WriteLine("Az " + (i + 1) + ". elem: " + array[i]);
  20.                
  21.             }
  22.            
  23.            
  24.  
  25.             if (tombkeres(array))
  26.             {
  27.                 Console.WriteLine("A szám benne van a tömbben.");
  28.             }
  29.             else
  30.             {
  31.                 Console.WriteLine("A szám nincs benne a tömbben.");
  32.             }
  33.  
  34.  
  35.         }
  36.  
  37.         static bool tombkeres(int[] tomb)
  38.         {
  39.             Console.Write("Kérem a keresendő számot: ");
  40.             int keres = int.Parse(Console.ReadLine());
  41.             for (int i = 0; i < tomb.Length; i++)
  42.             {
  43.                 if (keres == tomb[i])
  44.                 {
  45.                     return true;
  46.                 }
  47.             }
  48.             return false;
  49.         }
  50.  
  51.     }
  52. }
  53.  
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement