- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Kotlin Program to Add two Numbers
In this article, we will understand how to add two numbers. This can be done using the ‘+’ operator. Below is a demonstration of the same
Suppose our input is
input1 : 10 input2 : 15
The desired output would be
Sum : 25
Algorithm
Step 1 − Start
Step 2 − Declare three integers: val1, val2 and sum
Step 3 − Define the integers
Step 4 − Add the two values using an addition operator (+)
Step 5 − Display the result
Step 6 − Stop
Example 1
In this example, we will add two numbers using the + operator. First, declare and set two integers i.e. number −
val val1 = 10 val val2 = 15
Now, calculate the sum using the Addition Arithmetic Operator −
val sum = val1 + val2
Let us now see the complete example −
fun main() { val val1 = 10 val val2 = 15 println("The two numbers are defined as " +val1 +" and " +val2) val sum = val1 + val2 println("The sum of the two integers is: " +sum) }
Output
The two numbers are defined as 10 and 15 The sum of the two integers is: 25
Example 2
Here, we have created a custom function
fun sum(val1 : Int, val2 : Int){ val sum = val1 + val2 println("The sum of the two integers is: " +sum) } fun main() { val val1 = 10 val val2 = 15 println("The two numbers are defined as " +val1 +" and " +val2) sum(val1, val2) }
Output
The two numbers are defined as 10 and 15 The sum of the two integers is: 25
- Related Articles
- Kotlin Program to Add Two Complex numbers
- Kotlin Program to Swap Two Numbers
- Java Program to Add Two Numbers
- C++ Program to Add Two Numbers
- Python program to add two numbers
- Kotlin Program to Multiply Two Floating-Point Numbers
- Kotlin Program to Find GCD of two Numbers
- Kotlin Program to Find LCM of two Numbers
- Java Program to Add the two Numbers
- Java Program to Add Two Complex numbers
- Haskell program to add two complex numbers
- 8085 Program to Add two 8 Bit numbers
- 8051 Program to Add two 8 Bit numbers
- 8085 program to add two 16 bit numbers
- Program to Add Two Complex Numbers in C

Advertisements