#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int n, i, j, jmax, jmin; float a[50][50], min, max, sum = 0;
printf("N = "); scanf_s("%d", &n);
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
a[i][j] = rand() % 10 - 5.37;
printf("%7.3f", a[i][j]);
}
printf("\n");
max = a[i][1]; jmax = 1;
min = a[i][1]; jmin = 1;
if (a[i][j] > max)
max = a[i][j];
jmax = j;
if (a[i][j] < min)
min = a[i][j];
jmin = j;
float tmp = a[i][jmax];
a[i][jmax] = a[i][jmin];
a[i][jmin] = tmp;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i == j)
sum += a[i][j];
printf("Summa - %7.3f", sum);
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int n, i, j, jmax, jmin; float a[50][50], min, max, sum = 0;
printf("N = "); scanf_s("%d", &n);
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
a[i][j] = rand() % 10 - 5.37;
printf("%7.3f", a[i][j]);
}
printf("\n");
}
printf("\n");
for (i = 1; i <= n; i++)
{
max = a[i][1]; jmax = 1;
min = a[i][1]; jmin = 1;
for (j = 1; j <= n; j++)
{
if (a[i][j] > max)
{
max = a[i][j];
jmax = j;
}
if (a[i][j] < min)
{
min = a[i][j];
jmin = j;
}
}
float tmp = a[i][jmax];
a[i][jmax] = a[i][jmin];
a[i][jmin] = tmp;
for (j = 1; j <= n; j++)
printf("%7.3f", a[i][j]);
printf("\n");
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i == j)
{
sum += a[i][j];
}
printf("Summa - %7.3f", sum);
}