Skip to content

Instantly share code, notes, and snippets.

@resure
Created February 22, 2011 18:35
Show Gist options
  • Save resure/839126 to your computer and use it in GitHub Desktop.
Save resure/839126 to your computer and use it in GitHub Desktop.
Работа с массивами
#include <stdio.h>
#include <locale.h>
#define ARRAY_SIZE 10
using namespace std;
int main() {
setlocale(0, "russian");
float a[ARRAY_SIZE][ARRAY_SIZE];
float max, min;
int i, j, imax = 0, imin = 0, cnt = 0;
int list = 1, c, xdir = 0, dir = 0, d[4][4];
//srand( (unsigned)time( NULL ));
for (i = 0; i < ARRAY_SIZE; ++i)
{
for(size_t j = 0; j < ARRAY_SIZE; ++j)
{
a[i][j] = cnt++;
printf("%2.f ", a[i][j]);
}
printf("\n");
}
max = a[0][0];
for (i = 1; i < ARRAY_SIZE; i++)
for (j = 1; j < ARRAY_SIZE; j++)
if (max < a[i][j]) {
max = a[i][j];
imax = i;
}
min = a[imax][0];
for (i = 1; i < ARRAY_SIZE; i++)
if (min > a[imax][i]) {
min = a[imax][i];
imin = i;
}
printf("\n\nПервый максимальный элемент: %.2f\n", max);
printf("Первый минимальный элемент: %.2f\n\n", min);
for (i = imin; i < ARRAY_SIZE; i++)
printf("%.2f ", a[i][imin]);
printf("\n\n\n");
d[0][0] = 0; d[0][1] = 1;
d[1][0] = 1; d[1][1] = 0;
d[2][0] = 0; d[2][1] = -1;
d[3][0] = -1; d[3][1] = 0;
cnt = 1; i = j = ARRAY_SIZE / 2 - 1;
while (cnt < ARRAY_SIZE * ARRAY_SIZE) {
for (c = 0; c < list; c++, cnt++) {
printf("%2.f ", a[i][j]);
i += d[dir][0];
j += d[dir][1];
}
dir++;
xdir++;
if (dir > 3) dir = 0;
if ((xdir % 2) == 0) list++;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment