(HackerRank) Write a Modular C Programming code to solve 2D ARRAYS- Yollo algorithm, In a computer vision application, for object detection Yollo algorithm is used.
In a computer vision application, for object detection Yollo algorithm is used. The input for the algorithm is an image in the 2-D matrix format. The algorithm requires the matrix’s rows and columns to be interchanged.
Apply PSF to read the image and display the rotated image.
(HINT: Transpose of a matrix)
Input Format
First line is size of the image in the form mxn.
Constraints
m and n should be > 0.
Output Format
Rotated image.
Sample Input 0
1 2
10 20
Sample Output 0
10
20
Sample Input 1
0 0
Sample Output 1
Invalid image size.
CODE:
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int main() { int m,n,i,j; scanf("%d%d",&m,&n); if(m>0 && n>0) { int image[m][n]; int transpose[n][m]; for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&image[i][j]); transpose[j][i]=image[i][j]; } } for(i=0;i<n;i++) { for(j=0;j<m;j++) { printf("%d ",transpose[i][j]); } printf("\n"); } } else{ printf("Invalid image size."); } return 0; }
OUTPUT
Congratulations, you passed the sample test case. Click the Submit Code button to run your code against all the test cases. Input (stdin) 1 2 10 20 Your Output (stdout) 10 20 Expected Output 10 20
Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, Stacks, Queues, Binary Trees, MISC, Solved model question papers & Hacker Rank all solutions on the below page:
Top 100+ C Programming codes – KLE Technological University