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 N){
- int* maxArr = (int*)malloc(N*sizeof(int));
- for (int j = 0; j < N ; j++ ){
- int Max = mass[0][j];
- for (int i = 1; i < N; i++ ){
- if (mass[i][j] > Max){
- Max = mass[i][j];
- }
- }
- maxArr[j] = Max;
- }
- return maxArr;
- }
- int *getMin( int **mass, int N){
- int* minArr = (int*)malloc(N*sizeof(int));
- for (int i = 0; i < N; i++ ){
- int Min = mass[i][0];
- for (int j = 1; j < N; j++ ){
- if (mass[i][j] < Min){
- Min = mass[i][ j];
- }
- }
- minArr[i] = Min;
- }
- return minArr;
- }
- void getPoint(int **mass, int *minArr, int *maxArr, int N){
- FILE* out = fopen("D:\\Labs\\labs 2-3\\result C\\result.txt", "w+");
- int res = 0;
- for(int i = 0; i < N; i++ ){
- for(int j = 0; j < N; j++ ){
- if ((mass[i][j] == minArr[i]) && (mass[i][j] == maxArr[j])){
- fprintf(out,"The saddle point of this matrix is the number %d in %d-th line %d-th column.\n", (mass[i][j]), (i + 1), (j + 1));
- res += 1;
- }
- }
- }
- if (res == 0){
- fprintf(out,"There are no saddle points in this matrix.");
- }
- fclose(out);
- }
- int** getMatrix(){
- int arrLength;
- FILE* in = fopen("D:\\Labs\\labs 2-3\\text\\task.txt", "r+");
- fscanf(in,"%d", &arrLength);
- int** 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;
- }
- int arrLength(){
- int arrLength;
- FILE* in = fopen("D:\\Labs\\labs 2-3\\text\\task.txt", "rt");
- fscanf(in,"%d", &arrLength);
- fclose(in);
- int Length = arrLength;
- return Length;
- }
- void Main() {
- int Num = arrLength();
- int **Mass = getMatrix();
- getPoint(Mass, getMin(Mass, Num), getMax(Mass, Num), Num);
- }
- int main() {
- Main();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement