Advertisement
BloodMoonYTC

tombktolnulla

Oct 24th, 2021
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2.  
  3. namespace tombktolnulla
  4. {
  5.     class Program
  6.     {
  7.         static void KcsereNulla(int[] a, int k)
  8.         {
  9.             for (int i = 0; i < a.Length; i++)
  10.             {
  11.                 if (a[i] > k)
  12.                     a[i] = 0;
  13.             }
  14.         }
  15.         static void Main(string[] args)
  16.         {
  17.             int n, k;
  18.             while (true)
  19.             {
  20.                 Console.Write("A tömb elemeinek száma: ");
  21.                 n = int.Parse(Console.ReadLine());
  22.                 if (n <= 0) break;
  23.                 int[] t = new int[n];
  24.  
  25.                 Console.WriteLine("A tömb elemeinek beolvasása");
  26.                 for (int i = 0; i < n; i++)
  27.                 {
  28.                     Console.Write("{0}: ", i);
  29.                     t[i] = int.Parse(Console.ReadLine());
  30.                 }
  31.  
  32.                 Console.Write("A k értéke: ");
  33.                 k = int.Parse(Console.ReadLine());
  34.                 KcsereNulla(t, k);
  35.                 Console.WriteLine("A tömb elemeinek kiírása");
  36.                 for (int i = 0; i < n; i++)
  37.                 {
  38.                     Console.WriteLine("{0}: {1}", i, t[i]);
  39.                 }
  40.  
  41.                 Console.WriteLine("Kólity Kristóf");
  42.                 Console.WriteLine("Enter nyomásával újraindítható a program.");
  43.                 Console.ReadLine();
  44.             }
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement