Second task is done
This commit is contained in:
parent
d44cc8aeb9
commit
f9c0bee59c
4 changed files with 19 additions and 10 deletions
3
2025.03.21/02Ex/a.txt
Normal file
3
2025.03.21/02Ex/a.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
-10 -6 -2 2
|
||||
-9 -5 -1 3
|
||||
-8 -4 0 4
|
|
@ -59,7 +59,7 @@ int main(int argc, char *argv[])
|
|||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
printf("New matrix:\n");
|
||||
print_matrix(a, m, n - 1, p);
|
||||
print_matrix(a, m - 1, n - 1, p);
|
||||
printf ("%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
|
||||
|
||||
free(a);
|
||||
|
|
|
@ -3,18 +3,16 @@
|
|||
|
||||
#define eps 1e-17
|
||||
|
||||
int t1_solve(double *a, int m, int n)
|
||||
int t2_solve(double *a, int m, int n)
|
||||
{
|
||||
int l, min_i = 0, min_j = 0, del_j;
|
||||
double minimum = (m * n > 0) ? a[0] : 0;
|
||||
int min_i = 0, min_j = 0;
|
||||
double minimum = (m * n > 0) ? fabs(a[0]) : 0;
|
||||
|
||||
for (int i = 0; i < m; i++)
|
||||
for (int j = 0; j < n; j++)
|
||||
if ((minimum - a[i*n + j]) > eps) { minimum = a[i*n + j]; min_i = i; min_j = j; }
|
||||
if ((minimum - fabs(a[i*n + j])) > eps) { minimum = fabs(a[i*n + j]); min_i = i; min_j = j; }
|
||||
|
||||
(void)(min_i);
|
||||
|
||||
for (l = min_j+1, del_j = 1; l < m*n; l++)
|
||||
for (int l = min_j+1, del_j = 1; l < min_i*n; l++)
|
||||
{
|
||||
if (l == ((n * del_j) + min_j))
|
||||
del_j++;
|
||||
|
@ -22,5 +20,13 @@ int t1_solve(double *a, int m, int n)
|
|||
a[l - del_j] = a[l];
|
||||
}
|
||||
|
||||
return min_j + 1;
|
||||
for (int l = (min_i+1)*n, del_j = min_i; l < m*n; l++)
|
||||
{
|
||||
if (l == ((n * (del_j + 1)) + min_j))
|
||||
del_j++;
|
||||
else
|
||||
a[l - del_j - n] = a[l];
|
||||
}
|
||||
|
||||
return min_i * n + min_j;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
int t1_solve(double *a, int m, int n);
|
||||
int t2_solve(double *a, int m, int n);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue