Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void displayByRows(int rows, int cols, int arr[10][10])
- {
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- printf("%d ", arr[i][j]);
- }
- printf("\n");
- }
- }
- void displayByColumns(int rows, int cols, int arr[10][10])
- {
- for (int j = 0; j < cols; j++)
- {
- for (int i = 0; i < rows; i++)
- {
- printf("%d ", arr[i][j]);
- }
- printf("\n");
- }
- }
- void swapRowsAndColumns(int rows, int cols, int arr[10][10])
- {
- int temp[10][10];
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- temp[j][i] = arr[i][j];
- }
- }
- for (int i = 0; i < cols; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- arr[i][j] = temp[i][j];
- }
- }
- }
- int main()
- {
- int Rotate[10][10], rows, cols;
- printf("Enter the number of rows: ");
- scanf("%d", &rows);
- printf("Enter the number of columns: ");
- scanf("%d", &cols);
- printf("\n\nEnter the elements of the array:\n");
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- printf("Rotate[%d][%d] = ", i, j);
- scanf("%d", &Rotate[i][j]);
- }
- printf("\n");
- }
- printf("\n\nDisplay by rows:\n");
- displayByRows(rows, cols, Rotate);
- printf("\n\nDisplay by columns:\n");
- displayByColumns(rows, cols, Rotate);
- printf("\n\nInitiating swapping function ....\n");
- swapRowsAndColumns(rows, cols, Rotate);
- printf("\n\nAfter swapping rows and columns:\n");
- displayByRows(cols, rows, Rotate);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement