Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************************************************/
- /*Name: Liav Vaknin, Class: 41/5, ID: 303030340.*/
- /*Name: Alex Naidyonkov, Class: 41/5, ID: 321055071 */
- /****************************************************************************************/
- /* The function receives as parameters a two-dimensional matrix size NxN */
- /* and integer SIZE.The function will search matrix identical sequence */
- /* of numbers SIZE length, vertically and horizontally (not diagonally). */
- /* Print function matrix locations where such sequence begins. */
- /* Print their coordinates. */
- #include<stdio.h>
- #define N 5
- // function statement
- void func(int arr[][N], int size);
- // main statement
- void main()
- {
- int i, j, size;
- int arr[N][N]; // statment matrix NxN
- printf("Please enter matrix size:\n");
- scanf("%d", &size);
- printf("Please enter a numbers in to the matrix:\n");
- for (i = 0; i < N; i++) // create a 5*5 matrix using a 2 dimensional array
- {
- for (j = 0; j < N; j++)
- scanf("%d", &arr[i][j]);
- }
- printf("The entered matrix is:\n\n"); // print a 5*5 matrix after creating
- for (i = 0; i < N; i++)
- {
- for (j = 0; j < N; j++)
- printf("%3d", arr[i][j]);
- printf("\n\n");
- }
- func(arr, size); // send a martix and size in to the function
- }
- // set function
- void func(int arr[][N], int size)
- {
- int i, j, k;
- int count1 = 1, count2 = 1;
- for (j = 0; j < size; j++) // cheking in COLUMNS in the matrix the identical sequence of numbers
- {
- for (i = 0; i < size; i++)
- if (arr[i][j] == arr[i + 1][j])
- {
- count1++; // count a identical serial numbers in the ROWS
- }
- if (count1 == size) // if counter big more 3 - print coordinates
- {
- printf("\nsequence start in columns [%d][%d]\n", i - 2, j);
- count1 = 0; // reseting a counter
- }
- else if (count1 > size) // if counter more them 3 size search another array with 3 size array
- {
- printf("\nsequence start in columns [%d][%d]\n", i - 3, j);
- k = i + 2; // set a new variable
- for (k = 0; k < size; k++) // search and count a new aray with size 3
- if (arr[k][j] == arr[k+1][j])
- {
- count1++; // count a identical serial numbers in the ROWS again
- }
- printf("\nsequence start in columns [%d][%d]\n", k - 1, j);
- count1 = 0; // reseting a counter
- }
- }
- for (i = 0; i < size; i++) // cheking in ROWS in the matrix the identical sequence of numbers
- {
- for (j = 0; j <= size; j++)
- if (arr[i][j] == arr[i][j + 1])
- {
- count2++; // count a identical serial numbers in the COLUMNS
- }
- if (count2 == size)
- {
- printf("\nsequence start in rows [%d][%d]\n", i, j - 3);
- count2 = 0; // reseting a counter
- }
- else if (count2 > size) // if counter more them 3 size search another array with 3 size array
- {
- printf("\nsequence start in rows [%d][%d]\n", i, j - 3);
- k = j + 2; // set a new variable
- for (k = 0; k < size; k++) // search and count a new aray with size 3
- if (arr[i][k] == arr[i][k+1])
- {
- count2++; // count a identical serial numbers in the COLUMNS again
- }
- printf("\nsequence start in rows [%d][%d]\n", i, k-1);
- count2 = 0; // reseting a counter
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement