Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4.  
  5. int count_numbers(int *array, int m, int n, int matrix[][n])
  6. {
  7. for (int i = 0; i < m; i++)
  8. {
  9. for (int j = 0; j < n; j++)
  10. {
  11. while (abs(matrix[i][j]) > 0)
  12. {
  13. int k = abs(matrix[i][j] % 10);
  14. array[k]++;
  15. matrix[i][j] /= 10;
  16. }
  17. }
  18. }
  19. }
  20.  
  21.  
  22. void test_count_numbers(void)
  23. {
  24. int array[10] = {0};
  25. int error_count = 0, correct_count = 0;
  26. int matrix[2][2] = {{123, -321},
  27. {-190, 3015}};
  28. count_numbers(array, 2, 2, matrix);
  29. int array_test[10] = {2, 4, 2, 3, 0, 1, 0, 0, 0, 1};
  30. int count = 0;
  31. for (int i = 0; i < 10; i++)
  32. {
  33. if (array[i] == array_test[i])
  34. {
  35. count++;
  36. }
  37. }
  38. if (count == 10)
  39. { correct_count++; }
  40. else
  41. { error_count++; }
  42.  
  43.  
  44. int array2[10] = {0};
  45. int matrix2[1][1] = {{1}};
  46. count_numbers(array2, 1, 1, matrix2);
  47. int array_test2[10] = {0, 0, 0, 0, 1, 0, 0, 0, 0, 0};
  48. count = 0;
  49. for (int i = 0; i < 10; i++)
  50. {
  51. if (array2[i] == array_test2[i])
  52. {
  53. count++;
  54. }
  55. }
  56. if (count == 10)
  57. { correct_count++; }
  58. else
  59. { error_count++; }
  60.  
  61.  
  62. int array3[10] = {0};
  63. int matrix3[5][1] = {{4, 8, 4, 4, 8}};
  64. count_numbers(array3, 5, 1, matrix3);
  65. int array_test3[10] = {0, 0, 0, 0, 3, 0, 0, 0, 2, 0};
  66. count = 0;
  67. for (int i = 0; i < 10; i++)
  68. {
  69. if (array3[i] == array_test3[i])
  70. {
  71. count++;
  72. }
  73. }
  74. if (count == 10)
  75. { correct_count++; }
  76. else
  77. { error_count++; }
  78.  
  79.  
  80. int array4[10] = {0};
  81. int matrix4[2][2] = {{-5, -4},
  82. {-5, -3}};
  83. count_numbers(array4, 2, 2, matrix4);
  84. int array_test4[10] = {0, 0, 1, 1, 2, 0, 0, 0, 2, 0};
  85. count = 0;
  86. for (int i = 0; i < 10; i++)
  87. {
  88. if (array4[i] == array_test4[i])
  89. {
  90. count++;
  91. }
  92. }
  93. if (count == 10)
  94. { correct_count++; }
  95. else
  96. { error_count++; }
  97.  
  98.  
  99. int array5[10] = {0};
  100. int matrix5[2][2] = {{0, 12},
  101. {3456, 789}};
  102. count_numbers(array5, 2, 2, matrix5);
  103. int array_test5[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  104. count = 0;
  105. for (int i = 0; i < 10; i++)
  106. {
  107. if (array5[i] == array_test5[i])
  108. {
  109. count++;
  110. }
  111. }
  112. if (count == 10)
  113. { correct_count++; }
  114. else
  115. { error_count++; }
  116.  
  117. printf("Correct tests %d/5 \n", correct_count);
  118. printf("Incorrect tests %d/5", error_count);
  119. }
  120.  
  121. int main()
  122. {
  123. test_count_numbers();
  124. return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement