Код:
#include <iostream>
#include <stdio.h>
#include <clocale>
void transform (float **M,float *V,int n,int m);
int maxline(float **A,int n,int m);
void delline(float **A,int* n,int m, int index);
int readmat(int*n, int* m, float** A, int Nmax, int Mmax);
void writemat(float** A, int n, int m);
float* maxelem(float **A,int n,int m);
int main()
{
const int Nmax=18;
const int Mmax=20;
float E[Nmax][Mmax];
float * Ep[Nmax];
transform(Ep, *E, Nmax, Mmax);
int n, m;
if(!readmat(&n, &m, Ep, Nmax, Mmax ))
{
printf("Erorr size!!!\n");
return 0;
}
//int index = maxline(Ep, n, m);
float* P = maxelem(Ep, n, m);
printf("Maxelem=%lf\n",*P);
printf("Stroka=%ld\n" ,((P-E[0])%Nmax));
printf("stolbec=%ld\n",((P-E[0])/Nmax));
printf("matrix before\n");
writemat(Ep, n, m);
printf("\n");
delline(Ep, &n, m, (P - E[0])/Nmax);
printf("matrix after\n");
writemat(Ep, n, m);
return 1;
}
void transform (float **M,float *V,int n,int m)
{
for (int i = 0; i < n; i++)
M[i] = V + i*m;
}
int maxline(float **A,int n,int m)
{
float Amax = A[0][0];
int imax = 0;
for (int i = 0; i < n; i++)\
for (int j = 0; i < m; i++)
if(Amax < A[i][j])
{
Amax = A[i][j];
imax = i;
}
return imax;
}
float* maxelem(float **A,int n,int m)
{
float* Pmax = A[0];
for (int i = 0; i < n; i++)\
for (int j = 0; j < m; j++)
if(*Pmax < A[i][j])
{
Pmax = A[i] + j;
}
return Pmax;
}
void delline(float **A,int* n,int m, int index)
{
for (int i = index; i < *n - 1; i++)
for(int j = 0;j < m; j++)
A[i][j] = A[i+1][j];
--*n;
}
int readmat(int*n, int* m, float** A, int Nmax, int Mmax)
{
printf("(n*m): ");
scanf("%d%d", n, m);
if(*n <= 0 || *n > Nmax || *m <= 0 || *m > Mmax) return 0;
printf("Matrix: \n");
for(int i = 0; i < *n; i++)
for(int j = 0; j < *m; j++)
scanf("%f", A[i] + j);
return 1;
}
void writemat(float** A, int n, int m)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
printf(" %7.2f", A[i][j]);
printf("\n");
}
}