• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Oct 15th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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.     FILE* in = fopen("D:\\Labs\\labs 2-3\\text\\task.txt", "rt");
56.     fscanf(in,"%d", &arrLength);
57.     int** mass = (int**)malloc(arrLength*sizeof(int*));
58.     for (int i = 0; i < arrLength; i++){
59.         mass[i] = (int*)malloc(arrLength* sizeof(int));
60.         for (int j = 0; j < arrLength; j++) {
61.             fscanf(in, "%d", &mass[i, j]);
62.         }
63.     }
64.     fclose(in);
65.     return mass;
66. }
67.
68.  void Main(){
69.     int arrLength = 0;
70.     FILE* in = fopen("D:\\Labs\\labs 2-3\\text\\task.txt", "rt");
71.     fscanf(in,"%d", &arrLength);
72.     fclose(in);
73.     int** Mass = getMatrix();
74.     getPoint(Mass, getMin(Mass), getMax(Mass));
75. }
76.
77.
78. int main(){
79.     Main();
80.     return 0;
81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?