Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define SIZE 6
- #define MAX_VALUE 100
- void fillMatrix(int matrix[SIZE][SIZE]) {
- for (int i = 0; i < SIZE; i++) {
- for (int j = 0; j < SIZE; j++) {
- matrix[i][j] = rand() % (MAX_VALUE - 1) + 2;
- }
- }
- }
- void printMatrix(int matrix[SIZE][SIZE]) {
- for (int i = 0; i < SIZE; i++) {
- for (int j = 0; j < SIZE; j++) {
- printf("%3d ", matrix[i][j]);
- }
- printf("\n");
- }
- }
- void replaceElements(int matrix[SIZE][SIZE]) {
- int count[MAX_VALUE + 1] = {0};
- for (int i = 0; i < SIZE; i++) {
- for (int j = 0; j < SIZE; j++) {
- count[matrix[i][j]]++;
- }
- }
- for (int i = 0; i < SIZE; i++) {
- for (int j = 0; j < SIZE; j++) {
- if (count[matrix[i][j]] > 1) {
- matrix[i][j] = 1;
- } else {
- matrix[i][j] = 0;
- }
- }
- }
- }
- int main() {
- int matrix[SIZE][SIZE];
- srand(time(NULL));
- fillMatrix(matrix);
- printf("Исходная матрица:\n");
- printMatrix(matrix);
- replaceElements(matrix);
- printf("Матрица после замены:\n");
- printMatrix(matrix);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement