Advertisement
Guest User

Andris fájlba

a guest
Jan 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace fájlbaír
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. /*Állítsunk elő véletlenszerűúen 5 egész számot a [0,100]-ból, majd írjuk ki a számokat a képernyőre és a háttértárolóra a program BIN/DEBUG könyvtárba !*/
  15. int[] a = new int[5];
  16. Random vsz = new Random();
  17.  
  18. for (int i = 0; i < 5; i++)
  19. {
  20. a[i] = vsz.Next(0,101);
  21. //képernyőre iratjuk ki
  22. Console.Write("{0,5}", a[i]);
  23. }
  24. string fajlnev = "szamok.txt";//fizikai fájl
  25. StreamWriter ir = null; //logikai fájl
  26.  
  27. try
  28. {
  29. ir = new StreamWriter(fajlnev); //összekapcsol
  30. for (int i = 0; i < 5; i++)
  31. {
  32. ir.Write("{0,5}", a[i]);
  33. }
  34. ir.Close();
  35. }
  36. catch (IOException)
  37. {
  38. Console.WriteLine("I/O hiba");
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45. Console.ReadKey();
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement