Created
December 29, 2016 07:00
-
-
Save hygull/f6ffa4e2c41a52865357d7ac81bee131 to your computer and use it in GitHub Desktop.
To print a 2d slice columnwise(A simple hackerearth's practice problem) created by hygull - https://repl.it/EyBJ/0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Created on : 29/12/2016. | |
| Aim of program : To print a 2d slice columnwise(A simple hackerearth's practice problem). | |
| Coded by : Rishikesh Agrawani. | |
| Problem's link : https://www.hackerearth.com/practice/data-structures/arrays/multi-dimensional/tutorial/ | |
| */ | |
| package main | |
| import "fmt" | |
| func main() { | |
| /*Getting number of rows & columns*/ | |
| var rows, columns,i,j int8 | |
| fmt.Scanf("%d%d",&rows,&columns) | |
| //Creating a 2d slice | |
| a := make([][]int8, rows) | |
| for i = 0; i < rows; i++ { | |
| a[i] = make([]int8, columns) | |
| } | |
| //Storing the numbers into slice | |
| for i=0;i<rows;i++{ | |
| for j=0;j<columns;j++{ | |
| fmt.Scanf("%d",&a[i][j]) | |
| } | |
| } | |
| //Printing the matrix(2d slice)...Order by column | |
| for i=0;i<columns;i++{ | |
| for j=0;j<rows;j++{ | |
| fmt.Print(a[j][i]," ") | |
| } | |
| fmt.Println() | |
| } | |
| } | |
| /*INPUT:- | |
| 3 5 | |
| 13 4 8 14 1 | |
| 9 6 3 7 21 | |
| 5 12 17 9 3 | |
| */ | |
| /*OUTPUT:- | |
| 13 9 5 | |
| 4 6 12 | |
| 8 3 17 | |
| 14 7 9 | |
| 1 21 3 | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment