Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- int *getMax(int *mass){
- int arrLength = 0;
- int *maxArr = (int*)malloc(arrLength*sizeof(int));
- for (int j = 0; j < arrLength ; j++ ){
- int Max = mass[0, j];
- for (int i = 1; i < arrLength; i++ ){
- if (mass[i, j] > Max){
- Max = mass[i, j];
- }
- }
- maxArr[j] = Max;
- }
- return &maxArr;
- }
- int *getMin( int *mass){
- int arrLength;
- int *minArr = (int*)malloc(arrLength*sizeof(int));
- for (int i = 0; i < arrLength; i++ ){
- int Min = mass[i, 0];
- for (int j = 1; j < arrLength; j++ ){
- if (mass[i, j] < Min){
- Min = mass[i, j];
- }
- }
- minArr[i] = Min;
- }
- return &minArr;
- }
- void getPoint(int *mass, int *minArr, int *maxArr){
- int arrLength;
- int res = 0;
- for(int i = 0; i < arrLength; i++ ){
- for(int j = 0; j < arrLength; j++ ){
- if (mass[i, j] == minArr[i] && mass[i, j] == maxArr){
- printf("The saddle point is the number %d in %d -th line %d -th column", (mass[i, j]), (i + 1), (j + 1));
- res += 1;
- }
- }
- }
- if (res == 0){
- printf("There are no saddle points in this matrix.");
- }
- }
- int* getMatrix(){
- int arrLength;
- int* mass;
- FILE* in = fopen("D:\\Labs\\labs 2-3\\text\\task.txt", "rt");
- fscanf(in,"%d", &arrLength);
- mass = (int*)malloc(arrLength*sizeof(int*));
- for (int i = 0; i < arrLength; i++){
- mass[i] = (int*)malloc(arrLength*sizeof(int));
- for (int j = 0; j < arrLength; j++) {
- fscanf(in, "%d", &mass[i, j]);
- }
- }
- fclose(in);
- return &mass;
- }
- void Main(){
- int arrLength = 0;
- FILE* in = fopen("D:\\Labs\\labs 2-3\\text\\task.txt", "rt");
- fscanf(in,"%d", &arrLength);
- fclose(in);
- int* Mass = getMatrix();
- getPoint(&Mass, getMin(&Mass), getMax(&Mass));
- }
- int main(){
- Main();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement