Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int* transpose(int* arr, int len){
- static int offset = 0;
- if(offset == len - 1){
- return *(arr);
- }else{
- printf("offset = %d\n", offset);
- for (int i = 0; i < len - offset; i++){
- printf("%d <-> %d\n", *(arr + (offset)*len + i), *(arr + (len - i - 1)*len + (len - offset - 1)));
- int temp = *(arr + (offset)*len + i);
- *(arr + (offset)*len + i) = *(arr + (len - i - 1)*len + (len - offset - 1));
- *(arr + (len - i - 1)*len + (len - offset - 1)) = temp;
- }
- for (int i = 0; i < len; i++){
- for (int j = 0; j < len; j++){
- printf("%5d ", *(arr + i*len + j));
- }
- printf("\n");
- }
- offset++;
- return transpose(arr, len);
- }
- }
- int main()
- {
- printf("Hello world!\n");
- int *initial;
- int n;
- printf("Enter n: ");
- scanf("%d", &n);
- initial = (int*)malloc(n * n * sizeof(int));
- for (int i = 0; i < n; i++){
- for (int j = 0; j< n; j++){
- printf("arr[%d][%d] = ", i, j);
- scanf("%d", (initial + i*n + j));
- }
- }
- for (int i = 0; i < n; i++){
- for (int j = 0; j < n; j++){
- printf("%5d ", *(initial + i*n + j));
- }
- printf("\n");
- }
- transpose(initial, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement