mituri

[C#] wczytaj liczby binarne z txt i wypisz najwieksza

Oct 2nd, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. /*
  2.  
  3. a)Zdefiniuj klasę odczytującą dane z pliku napisy.txt ( w pliku znajdują się liczby binarne). Na
  4. konsole wypisz największą liczbę w zapisie binarnym.
  5. b)Stwórz klasę Disparity , z publicznie dostępną tablicą ,z metodą publiczną , która zwraca różnicę
  6. wszystkich liczb , oraz metodę ,która wypisuje na ekran wszystkie liczby podzielne przez 10.
  7.  
  8. */
  9.  
  10. namespace zad1
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. String path = @"C:\Users\mitura\Documents\Visual Studio
  17. 2005\Projects\zad1\zad1\text.txt";
  18. string line;
  19. long result = 0, max = 0;
  20. FileStream fs = new FileStream(path, FileMode.OpenOrCreate,
  21. FileAccess.ReadWrite);
  22. StreamReader sr = new StreamReader(fs);
  23. while ((line = sr.ReadLine()) != null)
  24. {
  25. Console.WriteLine(line);
  26. result = Convert.ToInt64(line, 2);
  27. //Console.WriteLine(result);
  28. if (result > max) max = result;
  29. }
  30.  
  31. Console.WriteLine(max);
  32.  
  33. Console.ReadKey();
  34. }
  35. }
  36. }
  37. */
  38.  
  39. /* ZAD 2
  40. class Disparity {
  41.  
  42. public int []tab;
  43.  
  44. public void pokazPodzielnePrzez10() {
  45. Console.WriteLine("DZIESIETNE:");
  46. int size = tab.Length;
  47. for (int i = 0; i < size; i++) {
  48. int tmp = tab[i];
  49. if(tmp%10==0) Console.WriteLine(tmp);
  50. }
  51. }
  52.  
  53. public void pokazRoznice() {
  54. Console.WriteLine("ROZNICE:");
  55. int size = tab.Length;
  56. for (int i = 0; i < size; i++){
  57. for (int j = 0; j < size; j++){
  58. int tmp1 = tab[i];
  59. int tmp2 = tab[j];
  60. if (tmp1 != tmp2) {
  61. if (tmp1 > tmp2) Console.WriteLine(tmp1 - tmp2);
  62. else Console.WriteLine(tmp2 - tmp1);
  63. }
  64. }
  65. }
  66. }
  67.  
  68. };
  69.  
  70.  
  71. namespace zad1
  72. {
  73. class Program
  74. {
  75. static void Main(string[] args)
  76. {
  77. Disparity dis = new Disparity();
  78. int[]tabTmp = new int[]{12,26,30,44,50};
  79. dis.tab = tabTmp;
  80. dis.pokazPodzielnePrzez10();
  81. dis.pokazRoznice();
  82.  
  83. Console.ReadKey();
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment