Is there any other way to printing mirror image of a matrix avoiding TLE?

this is what I could think of so far:

#include<stdio.h>
#define ll long long int
#define ull unsigned long long int
int main()
{
    int n, m, i, j;
    scanf("%d %d", &n, &m);
    ll arr[n][m];
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            scanf("%d", &arr[i][j]);
        }
        for(j=m;j>0;j--)
        {
            printf("%d ", arr[i][j]);
        }
        printf("\n");
    }
    return 0;
} 

here I have to invert the elements of a row. for example if I input: 1 2 3\n 4 5 6\n 7 8 9 then the program should print: 3 2 1\n 6 5 4\n 9 8 7 my program gives proper result but its exceeding the given time limit.



Read more here: https://stackoverflow.com/questions/65708609/is-there-any-other-way-to-printing-mirror-image-of-a-matrix-avoiding-tle

Content Attribution

This content was originally published by Sanzida Hossain at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: