Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication5
  7. {
  8. class Program
  9. {
  10. static Boolean flag = false;
  11. static int max1 = 0;
  12. static void Main(string[] args)
  13. {
  14. int max2 = 0;
  15. Console.WriteLine("Podaj wiersze");
  16. int i = Convert.ToInt32(Console.ReadLine());
  17. Console.WriteLine("Podaj kolumny");
  18. int j = Convert.ToInt32(Console.ReadLine());
  19. double[,] tab = new double[i, j];
  20. load(ref tab);
  21. show(tab);
  22. max1 = Max(tab);
  23. max2 = Max(tab);
  24. Console.WriteLine("Max1 : " + max1 + " Max2 : " + max2);
  25.  
  26.  
  27. Console.ReadKey();
  28. }
  29. static void load(ref double[,] tab)
  30. {
  31. Random xxx = new Random();
  32. for (int i = 0; i < tab.GetLength(0); i++)
  33. {
  34. for (int j = 0; j < tab.GetLength(1); j++)
  35. tab[i, j] = xxx.Next(0, 6);
  36. }
  37. }
  38. static void show(double[,] tab)
  39. {
  40. for (int i = 0; i < tab.GetLength(0); i++)
  41. {
  42. for (int j = 0; j < tab.GetLength(1); j++)
  43. Console.Write("{0} ", tab[i, j]);
  44. Console.WriteLine();
  45. }
  46. }
  47.  
  48. static int Max(int[,] tab)
  49. {
  50. int max = 0;
  51.  
  52. for (int i = 0; i < tab.GetLength(0); i++)
  53. for (int j = 0; j < tab.GetLength(1); j++)
  54. {
  55. if (!flag)
  56. {
  57. if (tab[i, j] > max) max = tab[i, j];
  58. }
  59. else
  60. {
  61. if (tab[i, j] > max && tab[i, j] != max1) max = tab[i, j];
  62. }
  63. }
  64.  
  65. if (!flag) flag = true;
  66.  
  67. return max;
  68. }
  69.  
  70.  
  71.  
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement