Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. void getMax(int number, int**mass){
  4.     int Max;
  5.     int* maxArr =(int*)malloc(number* sizeof(int));
  6.     for (int i = 0; i < number; i++) {
  7.         Max = mass[i][0];
  8.         for (int j = 1; j < number; j++) {
  9.             if (Max < mass[i][j]) {
  10.                 Max = mass[i][j];
  11.             }
  12.         }
  13.         maxArr[i] = Max;
  14.         printf("%d",maxArr[i]);
  15.     }
  16. }
  17.  
  18. int** getMatrix(){
  19.     int arrLength;
  20.     FILE* in = fopen("D:\\Labs\\labs 2-3\\text\\task.txt","r+");
  21.     fscanf(in, "%d", &arrLength);
  22.     int** Mass =(int**)malloc(arrLength*sizeof(int*));
  23.     for (int i = 0; i < arrLength; i++) {
  24.         Mass[i]=(int*)malloc(arrLength*sizeof(int));
  25.         for (int j= 0; j < arrLength; j++){
  26.             fscanf(in, "%d",&Mass[i][j]);
  27.         }
  28.     }
  29.     fclose(in);
  30.     return Mass;
  31. }
  32. int main() {
  33.     int arrLength;
  34.     FILE* fin = fopen("D:\\Labs\\labs 2-3\\text\\task.txt","r+");
  35.     fscanf(fin, "%d", &arrLength);
  36.     int Size = arrLength;
  37.     int** Mass = getMatrix();
  38.     printf("Данная программа строит вектор из наибольших чисел в строках матрицы");
  39.     getMax(Size, Mass);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement