Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- const int cols = 5;
- void initmas(int** B, int cols, int rows);
- void cyclemovevert(int** B, int cols, int rows);
- void printmas(int** B, int cols, int rows);
- void cyclemovevert1(int** B, int cols, int rows);
- void print_static(int A[][M], int n);
- void init_static(int A[][M], int n);
- void swap(int* a, int* b);
- int main()
- {
- srand(time(NULL));
- const int rows = 10;
- int A[rows][cols];
- /*init_static(A, N);
- print_static(A, N);*/
- int** B = (int**)malloc(sizeof(int*) * rows);
- for (int i = 0; i < rows; i++)
- {
- B[i] = (int*)malloc(sizeof(int) * cols);
- }
- initmas(B, cols, rows);
- printmas(B, cols, rows);
- cyclemovevert(B, cols, rows);
- printf("\n");
- //printmas(B, cols, rows);
- for (int i = 0; i <rows; i++)
- {
- free(B[i]);
- }
- free(B);
- return 0;
- }
- void init_static(int A[][M], int n)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < M; j++)
- {
- A[i][j] = rand() % 100;
- }
- }
- return;
- }
- void print_static(int A[][M], int n)
- {
- printf("static matrix\n");
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < M; j++)
- {
- printf("%3d", A[i][j]);
- }
- printf("\n");
- }
- printf("\n");
- return;
- }
- void initmas(int** B, int rows, int cols)
- {
- for (int i = 0; i < cols; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- B[i][j] = rand() % 100;
- }
- }
- }
- void printmas(int** B, int rows, int cols)
- {
- for (int i = 0; i < cols; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- printf("%3d", B[i][j]);
- }
- printf("\n");
- }
- }
- void cyclemovevert(int** B, int cols, int rows)
- {
- for (int i = 0; i < cols; i++)
- {
- if (i % cols == 0)
- break;
- else
- {
- for (int k = i; k > 0; k--)
- {
- for (int j = 1; j < rows; j++)
- {
- swap(&B[j][i], &B[j - 1][i]);
- }
- }
- }
- }
- }
- void cyclemovevertdown(int** B, int cols, int rows)
- {
- for (int i = cols-1; i >0; i--)
- {
- for (int k = i; k > 0; k--)
- {
- for (int j = 1; j < rows; j++)
- {
- swap(&B[j][i], &B[j - 1][i]);
- }
- }
- }
- }
- void swap(int* a, int *b)
- {
- int temp = *a;
- *a =*b;
- *b = temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement