Advertisement
mcgizmo

Untitled

Dec 28th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. /****************************************************************************************/
  2. /*Name: Liav Vaknin, Class: 41/5, ID: 303030340.*/
  3. /*Name: Alex Naidyonkov, Class: 41/5, ID: 321055071 */
  4. /****************************************************************************************/
  5. /* The function receives as parameters a two-dimensional matrix size NxN */
  6. /* and integer SIZE.The function will search matrix identical sequence */
  7. /* of numbers SIZE length, vertically and horizontally (not diagonally). */
  8. /* Print function matrix locations where such sequence begins. */
  9. /* Print their coordinates. */
  10.  
  11. #include<stdio.h>
  12. #define N 5
  13.  
  14. // function statement
  15. void func(int arr[][N], int size);
  16.  
  17. // main statement
  18. void main()
  19. {
  20. int i, j, size;
  21. int arr[N][N]; // statment matrix NxN
  22. printf("Please enter matrix size:\n");
  23. scanf("%d", &size);
  24. printf("Please enter a numbers in to the matrix:\n");
  25. for (i = 0; i < N; i++) // create a 5*5 matrix using a 2 dimensional array
  26. {
  27. for (j = 0; j < N; j++)
  28. scanf("%d", &arr[i][j]);
  29. }
  30. printf("The entered matrix is:\n\n"); // print a 5*5 matrix after creating
  31. for (i = 0; i < N; i++)
  32. {
  33. for (j = 0; j < N; j++)
  34. printf("%3d", arr[i][j]);
  35. printf("\n\n");
  36. }
  37. func(arr, size); // send a martix and size in to the function
  38.  
  39. }
  40.  
  41. // set function
  42. void func(int arr[][N], int size)
  43. {
  44. int i, j, k;
  45. int count1 = 1, count2 = 1;
  46. for (j = 0; j < size; j++) // cheking in COLUMNS in the matrix the identical sequence of numbers
  47. {
  48.  
  49. for (i = 0; i < size; i++)
  50. if (arr[i][j] == arr[i + 1][j])
  51. {
  52. count1++; // count a identical serial numbers in the ROWS
  53. }
  54. if (count1 == size) // if counter big more 3 - print coordinates
  55. {
  56. printf("\nsequence start in columns [%d][%d]\n", i - 2, j);
  57. count1 = 0; // reseting a counter
  58. }
  59. else if (count1 > size) // if counter more them 3 size search another array with 3 size array
  60. {
  61. printf("\nsequence start in columns [%d][%d]\n", i - 3, j);
  62. k = i + 2; // set a new variable
  63. for (k = 0; k < size; k++) // search and count a new aray with size 3
  64. if (arr[k][j] == arr[k+1][j])
  65. {
  66. count1++; // count a identical serial numbers in the ROWS again
  67. }
  68. printf("\nsequence start in columns [%d][%d]\n", k - 1, j);
  69. count1 = 0; // reseting a counter
  70. }
  71.  
  72. }
  73.  
  74. for (i = 0; i < size; i++) // cheking in ROWS in the matrix the identical sequence of numbers
  75. {
  76. for (j = 0; j <= size; j++)
  77. if (arr[i][j] == arr[i][j + 1])
  78. {
  79. count2++; // count a identical serial numbers in the COLUMNS
  80. }
  81. if (count2 == size)
  82. {
  83. printf("\nsequence start in rows [%d][%d]\n", i, j - 3);
  84. count2 = 0; // reseting a counter
  85. }
  86. else if (count2 > size) // if counter more them 3 size search another array with 3 size array
  87. {
  88. printf("\nsequence start in rows [%d][%d]\n", i, j - 3);
  89. k = j + 2; // set a new variable
  90. for (k = 0; k < size; k++) // search and count a new aray with size 3
  91. if (arr[i][k] == arr[i][k+1])
  92. {
  93. count2++; // count a identical serial numbers in the COLUMNS again
  94. }
  95. printf("\nsequence start in rows [%d][%d]\n", i, k-1);
  96. count2 = 0; // reseting a counter
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement