Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int count_numbers(int *array, int m, int n, int matrix[][n])
- {
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- while (abs(matrix[i][j]) > 0)
- {
- int k = abs(matrix[i][j] % 10);
- array[k]++;
- matrix[i][j] /= 10;
- }
- }
- }
- }
- void test_count_numbers(void)
- {
- int array[10] = {0};
- int error_count = 0, correct_count = 0;
- int matrix[2][2] = {{123, -321},
- {-190, 3015}};
- count_numbers(array, 2, 2, matrix);
- int array_test[10] = {2, 4, 2, 3, 0, 1, 0, 0, 0, 1};
- int count = 0;
- for (int i = 0; i < 10; i++)
- {
- if (array[i] == array_test[i])
- {
- count++;
- }
- }
- if (count == 10)
- { correct_count++; }
- else
- { error_count++; }
- int array2[10] = {0};
- int matrix2[1][1] = {{1}};
- count_numbers(array2, 1, 1, matrix2);
- int array_test2[10] = {0, 0, 0, 0, 1, 0, 0, 0, 0, 0};
- count = 0;
- for (int i = 0; i < 10; i++)
- {
- if (array2[i] == array_test2[i])
- {
- count++;
- }
- }
- if (count == 10)
- { correct_count++; }
- else
- { error_count++; }
- int array3[10] = {0};
- int matrix3[5][1] = {{4, 8, 4, 4, 8}};
- count_numbers(array3, 5, 1, matrix3);
- int array_test3[10] = {0, 0, 0, 0, 3, 0, 0, 0, 2, 0};
- count = 0;
- for (int i = 0; i < 10; i++)
- {
- if (array3[i] == array_test3[i])
- {
- count++;
- }
- }
- if (count == 10)
- { correct_count++; }
- else
- { error_count++; }
- int array4[10] = {0};
- int matrix4[2][2] = {{-5, -4},
- {-5, -3}};
- count_numbers(array4, 2, 2, matrix4);
- int array_test4[10] = {0, 0, 1, 1, 2, 0, 0, 0, 2, 0};
- count = 0;
- for (int i = 0; i < 10; i++)
- {
- if (array4[i] == array_test4[i])
- {
- count++;
- }
- }
- if (count == 10)
- { correct_count++; }
- else
- { error_count++; }
- int array5[10] = {0};
- int matrix5[2][2] = {{0, 12},
- {3456, 789}};
- count_numbers(array5, 2, 2, matrix5);
- int array_test5[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- count = 0;
- for (int i = 0; i < 10; i++)
- {
- if (array5[i] == array_test5[i])
- {
- count++;
- }
- }
- if (count == 10)
- { correct_count++; }
- else
- { error_count++; }
- printf("Correct tests %d/5 \n", correct_count);
- printf("Incorrect tests %d/5", error_count);
- }
- int main()
- {
- test_count_numbers();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement