ADVERTISEMENT
ADVERTISEMENT

Home » Kotlin » Kotlin programs » Kotlin basic programs

Kotlin program to print the multiplication table of given number

Kotlin | printing multiplication table: Here, we are going to learn how to print the multiplication table of a given number in Kotlin programming language?
Submitted by IncludeHelp, on April 17, 2020

Given an integer number, we have to print its multiplication table.

To print a multiplication table, we run a loop starting from 1 to 10 and print the multiplication of the number with the loop variable/counter.

In the below program, we are creating a Kotlin program for printing the multiplication table.

Program to print the multiplication table in Kotlin

package com.includehelp.basic

import java.util.*

// Main function entry point of program
fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    println("Enter Number: ")
    val num: Int = sc.nextInt() 

    // for loop to print multiplication table of given number
    for (i in 1..10) {
        val result = num * i
        println("$num*$i = $result")
    }
}

Output

Enter Number:
5
5*1 = 5
5*2 = 10
5*3 = 15
5*4 = 20
5*5 = 25
5*6 = 30
5*7 = 35
5*8 = 40
5*9 = 45
5*10 = 50
------
Run 2:
Enter Number:
12
12*1 = 12
12*2 = 24
12*3 = 36
12*4 = 48
12*5 = 60
12*6 = 72
12*7 = 84
12*8 = 96
12*9 = 108
12*10 = 120
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.