#include <stdio.h>
#include <string.h>
#include <math.h>
#define M 2
#define N 2
void fun(int b, double a[][N], double t)
{
for (int i = 0; i < N; ++i)
{
// printf("asdas\n");
// printf("t = %f\n", t);
*(*(a + b) + i) /= t;
// printf("a[b][i] = %f\n", a[b][i]);
// a[b][i] = a[b][i] / t;
// printf("a[b][i] / t = %f\n", a[b][i] / t);
}
}
void fun2(double a[][N], void (*p)(int, double (*)[N], double))
{
double t = 0;
for (int i = 0; i < M; ++i)
{
t = fabs(*(*(a + i) + 0));
// t = fabs(a[i][0]);
for (int j = 0; j < N; ++j)
{
if (t < fabs(*(*(a + i) + j)))
{
t = fabs(*(*(a + i) + j));
}
// if (t < fabs(a[i][j]))
// {
// t = fabs(a[i][j]);
// }
}
p(i, a, t);
}
}
int main(int argc, char const *argv[])
{
double a[M][N];
void (*p)(int, double (*)[N], double);
p = fun;
for (int i = 0; i < M; ++i)
{
for (int j = 0; j < N; ++j)
{
scanf("%lf", &a[i][j]);
}
}
fun2(a, p);
for (int i = 0; i < M; ++i)
{
for (int j = 0; j < N; ++j)
{
printf("%f ", a[i][j]);
}
printf("\n");
}
return 0;
}
将double类型二维数组的每一行同除以该行上绝对值最大的元素
最新推荐文章于 2023-03-23 20:25:47 发布