94.6k views
4 votes
How to combine two integers​

User Jezbers
by
5.1k points

1 Answer

7 votes

The simplest approach to do this is:

Convert both numbers to string

Concatenate both strings into one, as this is comparatively easy

Convert this concatenated string back to integer

Explanation:

Given two integers n1 and n2, the task is to concatenate these two integers into one integer.

Example:

Input: n1 = 12, n2 = 34

Output: 1234

Input: n1 = 1, n2 = 93

Output: 193

User Greg Zuber
by
5.1k points