Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- Exemplu:
- matrice.in matrice.out
- 3 4 7 9 10
- 2 -1 7 4 2 -1 7 -6
- 6 9 8 1
- 9 8 10 -6
- using System;
- using System.IO;
- public class Program
- {
- public static void Main()
- {
- string linii="";
- linii=File.ReadAllText(@"|DataDirectory|\matrice.in");
- string[] numere=linii.Split(' ');
- int[,] matrice=new int[3,4];
- int m=int.Parse(numere[0]);//linii
- int n=int.Parse(numere[1]);//coloane
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- matrice[i,j]=int.Parse(numere[(n*i+j+2)]);
- }
- }
- int[] max=new int[m];
- int[] min=new int[n];
- for(int j=0;j<m;j++)
- {
- max[j]=matrice[0,j];
- for(int i=1;i<m;i++)
- {
- if(matrice[i,j]>matrice[i-1,j])
- {
- max[j]=matrice[i,j];
- }
- }
- }
- for(int i=0;i<n;i++)
- {
- min[i]=matrice[i,0];
- for(int j=1;j<n;j++)
- {
- if(matrice[i,j]<matrice[i,j-1])
- {
- min[j]=matrice[i,j];
- }
- }
- }
- string rezultate="";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement