Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1)
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- const int m = 10, n = 20;
- int random(int r)
- {
- return rand() % r;
- }
- int main()
- {
- int i, j, A[m][n], temp;
- for (i = 0; i < m; i++)
- for (j = 0; j < n; j++)
- A[i][j] = random(20);
- for (i = 0; i < m; i++)
- {
- for (j = 0; j < n; j++)
- printf("%4d", A[i][j]);
- printf("\n");
- }
- for (i = 0; i < m; i += 2)
- for (j = 0; j < n; j++)
- {
- temp = A[i][j];
- A[i][j] = A[i + 1][j];
- A[i + 1][j] = temp;
- }
- printf("\n");
- for (i = 0; i < m; i++)
- {
- for (j = 0; j < n; j++)
- printf("%4d", A[i][j]);
- printf("\n");
- }
- }
- -----------------------------------------------------
- 2)
- #include <stdio.h>
- #include <stdlib.h>
- const int n = 5;
- int main()
- {
- float A[n][n], summ = 0, a = 5.0;
- int i, j, j1;
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- A[i][j] = (float)rand() / (float)(RAND_MAX)*a;
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- printf("%10f", A[i][j]);
- printf("\n");
- }
- printf("\n");
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- summ += A[i][j];
- for (j1 = 0; j1 < n; j1++)
- A[i][j1] /= summ;
- summ = 0;
- }
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- printf("%10f", A[i][j]);
- printf("\n");
- }
- }
- ---------------------------------------------------------
- 3)
- #include <stdio.h>
- #include <stdlib.h>
- const int n = 5;
- int random(int r)
- {
- return rand() % r;
- }
- int main()
- {
- int i, j, A[n][n], B[n][n];
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- A[i][j] = random(10);
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- printf("%4d", A[i][j]);
- printf("\n");
- }
- printf("\n");
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- B[i][j] = A[j][i];
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- printf("%4d", B[i][j]);
- printf("\n");
- }
- }
- ---------------------------------------------------------
- 4)
- #include <stdio.h>
- #include <stdlib.h>
- const int n = 3;
- int random(int r)
- {
- return rand() % r;
- }
- int main()
- {
- int A[n][n], i, j, summ = 0, flag = 0, count = 0, S[6], c = 0;
- while (flag != 1)
- {
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- A[i][j] = random(10);
- count += 1;
- }
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- summ += A[i][j];
- S[c] = summ;
- c += 1;
- summ = 0;
- }
- for (j = 0; j < n; j++)
- {
- for (i = 0; i < n; i++)
- summ += A[i][j];
- S[c] = summ;
- c += 1;
- summ = 0;
- }
- c = 0;
- for (i = 0; i < 6; i++)
- {
- if (S[i] == S[i + 1])
- c += 1;
- }
- if (c == 5)
- flag = 1;
- else
- c = 0;
- }
- printf("%d", count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement