Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- public class MyProgram
- {
- private static Random random = new Random();
- public static void Main(string[] args)
- {
- /* kis csalás van benne
- mert nem egy kétdimenziós tömböt, hanem csak egy egydimenziósat használunk
- */
- int[] t = new int[15];
- int i, min, max, paros, j, cs;
- // inicianizálni kell a változókat, holott biztosan kapnak a későbbiek során értéket
- min = 0;
- max = 0;
- // Tömb feltöltése véletlen számokkal, egyben a legnagyobb, a legkisebb elemet is meghatározzuk
- for (i = 0; i <= 14; i++)
- {
- t[i] = random.Next(501) + 500;
- if (i == 0)
- {
- min = t[i];
- max = t[i];
- }
- else
- {
- if (t[i] < min)
- {
- min = t[i];
- }
- else
- {
- if (t[i] > max)
- {
- max = t[i];
- }
- }
- }
- Console.Write(t[i] + " ");
- // ez a feltétel felel a mátrixos megjelenítésért
- if (i % 5 == 4)
- {
- Console.WriteLine();
- }
- }
- Console.WriteLine("\nLekisebb elem: " + min);
- Console.WriteLine("Legnagyobb elem: " + max);
- // rendezzük a teljes tömböt
- for (i = 0; i < 13; i++)
- {
- for (j = i + 1; j < 14; j++)
- {
- if (t[i] > t[j])
- {
- cs = t[i];
- t[i] = t[j];
- t[j] = cs;
- }
- }
- }
- Console.WriteLine("\nPáros elemek növekvő sorrendben");
- // kiíratjuk a párosokat
- for (i = 0; i < 14; i++)
- {
- if (t[i]%2==0) {
- Console.Write(t[i]+" ");
- }
- }
- // file-ba írás
- using (StreamWriter stream = new StreamWriter("auto.txt", false))
- {
- stream.WriteLine(min.ToString());
- stream.WriteLine(max.ToString());
- for (i = 0; i < 14; i++)
- {
- if (t[i]%2==0) {
- stream.WriteLine(t[i].ToString());
- }
- }
- }
- Console.WriteLine("\n\nfile-ba írás kész!");
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement