Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3.  
  4.  
  5.  
  6.  int *getMax(int *mass){
  7.     int arrLength = 0;
  8.     int *maxArr = (int*)malloc(arrLength*sizeof(int));
  9.     for (int j = 0; j < arrLength ; j++ ){
  10.         int Max = mass[0, j];
  11.         for (int i = 1; i < arrLength; i++ ){
  12.             if (mass[i, j] > Max){
  13.                 Max = mass[i, j];
  14.             }
  15.         }
  16.         maxArr[j] = Max;
  17.     }
  18.     return &maxArr;
  19. }
  20.  
  21.  
  22.  int *getMin( int *mass){
  23.         int arrLength;
  24.         int *minArr = (int*)malloc(arrLength*sizeof(int));
  25.         for (int i = 0; i < arrLength; i++ ){
  26.             int Min = mass[i, 0];
  27.             for (int j = 1; j < arrLength; j++ ){
  28.                 if (mass[i, j] < Min){
  29.                     Min = mass[i, j];
  30.                 }
  31.             }
  32.             minArr[i] = Min;
  33.         }
  34.         return &minArr;
  35. }
  36.  
  37.  void getPoint(int *mass, int *minArr, int *maxArr){
  38.     int arrLength;
  39.     int res = 0;
  40.     for(int i = 0; i < arrLength; i++ ){
  41.         for(int j = 0; j < arrLength; j++ ){
  42.             if (mass[i, j] == minArr[i] && mass[i, j] == maxArr){
  43.                 printf("The saddle point is the number %d in %d -th line %d -th column", (mass[i, j]), (i + 1), (j + 1));
  44.                 res += 1;
  45.             }
  46.         }
  47.     }
  48.     if (res == 0){
  49.         printf("There are no saddle points in this matrix.");
  50.     }
  51. }
  52.  
  53.  int* getMatrix(){
  54.     int arrLength;
  55.     int* mass;
  56.     FILE* in = fopen("D:\\Labs\\labs 2-3\\text\\task.txt", "rt");
  57.     fscanf(in,"%d", &arrLength);
  58.     mass = (int*)malloc(arrLength*sizeof(int*));
  59.     for (int i = 0; i < arrLength; i++){
  60.         mass[i] = (int*)malloc(arrLength*sizeof(int));
  61.         for (int j = 0; j < arrLength; j++) {
  62.             fscanf(in, "%d", &mass[i, j]);
  63.         }
  64.     }
  65.     fclose(in);
  66.     return &mass;
  67. }
  68.  
  69.  void Main(){
  70.     int arrLength = 0;
  71.     FILE* in = fopen("D:\\Labs\\labs 2-3\\text\\task.txt", "rt");
  72.     fscanf(in,"%d", &arrLength);
  73.     fclose(in);
  74.     int* Mass = getMatrix();
  75.     getPoint(&Mass, getMin(&Mass), getMax(&Mass));
  76. }
  77.  
  78.  
  79. int main(){
  80.     Main();
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement