Advertisement
miljdze

Untitled

Dec 22nd, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7.  
  8. namespace ConsoleApplication188
  9. {
  10. class Program
  11. {
  12. static int[,] ProcitajINapravi(string lokacija)
  13. {
  14. StreamReader sr = new StreamReader(lokacija);
  15. int[,] matrica = new int[3, 7];
  16. string line;
  17. for (int i = 0; ((line = sr.ReadLine()) != null); i++)
  18. {
  19. string[] numbers = line.Split(',');
  20. for (int j = 0; j < matrica.GetLength(1); j++)
  21. {
  22. matrica[i, j] = int.Parse(numbers[j]);
  23. }
  24. }
  25. sr.Close();
  26. return matrica;
  27. }
  28.  
  29. static int SumaPetica(int[,] matrica)
  30. {
  31. int suma = 0;
  32. for (int i = 0; i < matrica.GetLength(0); i++)
  33. {
  34. for (int j = 0; j < matrica.GetLength(1); j++)
  35. {
  36. if (matrica[i, j] == 5)
  37. {
  38. suma = suma + matrica[i, j];
  39. }
  40. }
  41. }
  42. return suma;
  43. }
  44. static int NajveciSaPet(int[,] matrica)
  45. {
  46. int najveci = matrica[0,0];
  47. for (int i = 0; i < matrica.GetLength(0); i++)
  48. {
  49. for (int j = 0; j < matrica.GetLength(1); j++)
  50. {
  51. if (najveci < matrica[i, j])
  52. {
  53. najveci = matrica[i, j];
  54. }
  55. }
  56. }
  57. return najveci;
  58. }
  59. static void Main(string[] args)
  60. {
  61. StreamWriter sw = new StreamWriter("Matrica.txt");
  62. string lokacija = @"C:\Users\Milan\Desktop\FTN\UUP\Zadaca10\Brojevi.txt";
  63. int[,] matrica1 = ProcitajINapravi(lokacija);
  64. int sumapetica = SumaPetica(matrica1);
  65. int najvecisapet = NajveciSaPet(matrica1);
  66. int rezultat;
  67.  
  68. rezultat = najvecisapet * sumapetica;
  69. sw.WriteLine("Rezultat");
  70. sw.WriteLine("{0}", rezultat);
  71. sw.Close();
  72.  
  73.  
  74.  
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement