Advertisement
Guest User

Untitled

a guest
May 27th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. 20. Se citeste din fisierul matrice.in o matrice nepatratica astfel: de pe prima linie numarul de linii m si numarul de coloane n ( n,m<10). Sa se retina intr-un vector elementele maxime de pe fiecare linie, iar in alt vector elementele minime de pe fiecare coloana. Sa se afiseze cei doi vectori pe cate o linie in fisierul matrice.out, elementele fiecarei linii fiind despartite printr-un spatiu.
  2.  
  3. Exemplu:
  4. matrice.in matrice.out
  5. 3 4 7 9 10
  6. 2 -1 7 4 2 -1 7 -6
  7. 6 9 8 1
  8. 9 8 10 -6
  9.  
  10.  
  11.  
  12. using System;
  13. using System.IO;
  14.  
  15. public class Program
  16. {
  17. public static void Main()
  18. {
  19. string linii="";
  20. linii=File.ReadAllText(@"|DataDirectory|\matrice.in");
  21. string[] numere=linii.Split(' ');
  22. int[,] matrice=new int[3,4];
  23. int m=int.Parse(numere[0]);//linii
  24. int n=int.Parse(numere[1]);//coloane
  25. for(int i=0;i<n;i++)
  26. {
  27. for(int j=0;j<m;j++)
  28. {
  29. matrice[i,j]=int.Parse(numere[(n*i+j+2)]);
  30. }
  31. }
  32. int[] max=new int[m];
  33. int[] min=new int[n];
  34. for(int j=0;j<m;j++)
  35. {
  36. max[j]=matrice[0,j];
  37. for(int i=1;i<m;i++)
  38. {
  39. if(matrice[i,j]>matrice[i-1,j])
  40. {
  41. max[j]=matrice[i,j];
  42. }
  43. }
  44. }
  45. for(int i=0;i<n;i++)
  46. {
  47. min[i]=matrice[i,0];
  48. for(int j=1;j<n;j++)
  49. {
  50. if(matrice[i,j]<matrice[i,j-1])
  51. {
  52. min[j]=matrice[i,j];
  53. }
  54. }
  55. }
  56. string rezultate="";
  57.  
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement