Commit c6c884da by glkink

Add new file

parent 69e049be
Showing with 93 additions and 0 deletions
#include <stdio.h>
int main()
{
char *failinimi = "maatriks.txt";
FILE *fail = fopen(failinimi, "r");
if (fail == NULL)
{
printf("Ei saa faili avada!\n");
return 1;
}
int n;
fscanf(fail, "%d", &n);
int maatriks[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
fscanf(fail, "%d", &maatriks[i][j]);
}
}
int maksimum[n], miinimum[n], vahemik[n];
for (int i = 0; i < n; i++)
{
maksimum[i] = maatriks[0][i];
miinimum[i] = maatriks[0][i];
for (int j = 0; j < n; j++)
{
if (maatriks[j][i] > maksimum[i])
{
maksimum[i] = maatriks[j][i];
}
if (maatriks[j][i] < miinimum[i])
{
miinimum[i] = maatriks[j][i];
}
}
vahemik[i] = maksimum[i] - miinimum[i];
}
int ajutine;
int ajutineMassiiv[n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n - 1; j++)
{
if (vahemik[j] < vahemik[j + 1])
{
ajutine = vahemik[j];
vahemik[j] = vahemik[j + 1];
vahemik[j + 1] = ajutine;
for (int k = 0; k < n; k++)
{
ajutineMassiiv[k] = maatriks[k][j];
maatriks[k][j] = maatriks[k][j + 1];
maatriks[k][j + 1] = ajutineMassiiv[k];
}
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
printf("%5d ", maatriks[i][j]);
}
printf("\n");
}
printf("\n");
for (int i = 0; i < n; i++)
{
printf("%5d ", vahemik[i]);
}
printf("\n");
}
12
0 101 218 316 348 359 386 783 660 1169 371 996
-133 0 140 82 404 181 679 605 925 653 1059 1055
-170 -25 0 44 265 284 372 551 817 807 711 843
-343 -273 -138 0 109 250 247 508 686 219 916 1118
-534 -313 -263 -96 0 132 256 183 166 565 410 673
-61 -451 -275 -276 -65 0 72 262 323 476 378 479
-681 -655 -463 -282 -67 -125 0 45 155 414 462 688
-928 -710 -434 -443 -394 -104 -94 0 61 201 320 464
-893 -245 -630 -531 -414 -137 -219 -74 0 122 278 237
-781 -846 -681 -836 -563 -337 -259 -165 -7 0 109 219
-1324 -705 -130 -989 -620 -644 -545 -23 -190 -121 0 137
-522 -807 -444 -1083 -929 -804 -356 -411 -415 -139 -90 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment