Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int mas1[] = { 255, 1024, -2, -1 };
- for (int i = 0; i < 4; i++) printf("%d ", mas1[i]);
- printf("\n");
- short flag = 0;
- for (int i = 3; i > 0; i--) {
- int tmp = 0;
- short cnt = 0;
- for(int j = 0; j < i; j++)
- if (mas1[j] >= mas1[j + 1]) {
- tmp = mas1[j];
- mas1[j] = mas1[j + 1];
- mas1[j + 1] = tmp;
- cnt++;
- flag = 1;
- }
- printf("i= %d swaps: %d\n", i, cnt);
- if (cnt == 0) break;
- }
- if (flag) {
- printf("Sorted array: \n");
- for (int i = 0; i < 4; i++) printf("%d ", mas1[i]);
- printf("\n\n");
- }
- else printf("Array was sorted already\n");
- int mas2[3][3] = {
- {16, 24, 30},
- {43, 7, 63},
- {73, 82, 101}
- };
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) printf("%d ", mas2[i][j]);
- printf("\n");
- }
- int min = 2147483647;
- int im, ij;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- if (mas2[i][j] < min) {
- min = mas2[i][j];
- im = i;
- ij = j;
- }
- }
- }
- printf("\n");
- printf("min element: %d \ni:%d j:%d\n", min, im, ij);
- printf("\n");
- for (int i = 0, j = 0; i < 3; i++, j++) mas2[i][j] = min;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) printf("%d ", mas2[i][j]);
- printf("\n");
- }
- printf("\n");
- int sum1 = 0;
- int sum2 = 0;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- if (i == 0) sum1 += mas2[i][j];
- if (i == 2) sum2 += mas2[i][j];
- }
- }
- printf("sum1:%d \nsum2:%d\n", sum1, sum2);
- mas2[0][2] = sum1;
- mas2[2][0] = sum2;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) printf("%d ", mas2[i][j]);
- printf("\n");
- }
- printf("\n");
- int line1 = 0;
- int line2 = 2;
- for (int i = 0; i < 3; i++) {
- int tmp = mas2[line1][i];
- mas2[line1][i] = mas2[line2][i];
- mas2[line2][i] = tmp;
- }
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) printf("%d ", mas2[i][j]);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement