September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
17
Task/Identity-matrix/Kotlin/identity-matrix.kotlin
Normal file
17
Task/Identity-matrix/Kotlin/identity-matrix.kotlin
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// version 1.0.6
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
print("Enter size of matrix : ")
|
||||
val n = readLine()!!.toInt()
|
||||
println()
|
||||
val identity = Array(n) { IntArray(n) } // create n x n matrix of integers
|
||||
|
||||
// enter 1s in diagonal elements
|
||||
for(i in 0 until n) identity[i][i] = 1
|
||||
|
||||
// print identity matrix if n <= 40
|
||||
if (n <= 40)
|
||||
for (i in 0 until n) println(identity[i].joinToString(" "))
|
||||
else
|
||||
println("Matrix is too big to display on 80 column console")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue