# How to concatenate two Integer values into one?

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
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: 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

Program:

## C++

 `// CPP program to concatenate ` `// two integers into one ` ` `  `#include ` `#include ` `using` `namespace` `std; ` ` `  `// Function to concatenate ` `// two integers into one ` `int` `concat(``int` `a, ``int` `b) ` `{ ` ` `  `    ``// Convert both the integers to string ` `    ``string s1 = to_string(a); ` `    ``string s2 = to_string(b); ` ` `  `    ``// Concatenate both strings ` `    ``string s = s1 + s2; ` ` `  `    ``// Convert the concatenated string ` `    ``// to integer ` `    ``int` `c = stoi(s); ` ` `  `    ``// return the formed integer ` `    ``return` `c; ` `} ` ` `  `int` `main() ` `{ ` `    ``int` `a = 23; ` `    ``int` `b = 43; ` ` `  `    ``cout << concat(a, b) << endl; ` ` `  `    ``return` `0; ` `} ` ` `  `// This code is contributed by Ayush Singla(@ayusin51) `

## C

 `// C program to concatenate ` `// two integers into one ` ` `  `#include ` `#include ` `#include ` ` `  `// Function to concatenate ` `// two integers into one ` `int` `concat(``int` `a, ``int` `b) ` `{ ` ` `  `    ``char` `s1; ` `    ``char` `s2; ` ` `  `    ``// Convert both the integers to string ` `    ``sprintf``(s1, ``"%d"``, a); ` `    ``sprintf``(s2, ``"%d"``, b); ` ` `  `    ``// Concatenate both strings ` `    ``strcat``(s1, s2); ` ` `  `    ``// Convert the concatenated string ` `    ``// to integer ` `    ``int` `c = ``atoi``(s1); ` ` `  `    ``// return the formed integer ` `    ``return` `c; ` `} ` ` `  `int` `main() ` `{ ` `    ``int` `a = 23; ` `    ``int` `b = 43; ` ` `  `    ``printf``(``"%d\n"``, concat(a, b)); ` ` `  `    ``return` `0; ` `} ` ` `  `// This code is contributed by Ayush Singla(@ayusin51) `

## Java

 `// Java program to concatenate ` `// two integers into one ` ` `  `public` `class` `GFG { ` ` `  `    ``// Function to concatenate ` `    ``// two integers into one ` `    ``static` `int` `concat(``int` `a, ``int` `b) ` `    ``{ ` ` `  `        ``// Convert both the integers to string ` `        ``String s1 = Integer.toString(a); ` `        ``String s2 = Integer.toString(b); ` ` `  `        ``// Concatenate both strings ` `        ``String s = s1 + s2; ` ` `  `        ``// Convert the concatenated string ` `        ``// to integer ` `        ``int` `c = Integer.parseInt(s); ` ` `  `        ``// return the formed integer ` `        ``return` `c; ` `    ``} ` ` `  `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` `        ``int` `a = ``23``; ` `        ``int` `b = ``43``; ` ` `  `        ``System.out.println(concat(a, b)); ` `    ``} ` `} `

## Python3

 `# Python3 program to concatenate ` `# two integers into one ` ` `  `# Function to concatenate ` `# two integers into one ` `def` `concat(a, b): ` `     `  `    ``# Convert both the integers to string ` `    ``s1 ``=` `str``(a) ` `    ``s2 ``=` `str``(b) ` `     `  `    ``# Concatenate both strings     ` `    ``s ``=` `s1 ``+` `s2 ` `     `  `    ``# Convert the concatenated string ` `    ``# to integer ` `    ``c ``=` `int``(s) ` `     `  `    ``# return the formed integer ` `    ``return` `c ` ` `  `# Driver code ` ` `  `a ``=` `23` `b ``=` `43` ` `  `print``(concat(a, b)) ` ` `  `# This code is contributed by shubhamsingh10 `

## C#

 `// C# program to concatenate ` `// two integers into one ` `using` `System; ` ` `  `class` `GFG ` `{ ` ` `  `    ``// Function to concatenate ` `    ``// two integers into one ` `    ``static` `int` `concat(``int` `a, ``int` `b) ` `    ``{ ` ` `  `        ``// Convert both the integers to string ` `        ``String s1 = a.ToString(); ` `        ``String s2 = b.ToString(); ` ` `  `        ``// Concatenate both strings ` `        ``String s = s1 + s2; ` ` `  `        ``// Convert the concatenated string ` `        ``// to integer ` `        ``int` `c = ``int``.Parse(s); ` ` `  `        ``// return the formed integer ` `        ``return` `c; ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `Main(String []args) ` `    ``{ ` `        ``int` `a = 23; ` `        ``int` `b = 43; ` ` `  `        ``Console.WriteLine(concat(a, b)); ` `    ``} ` `} ` ` `  `/* This code contributed by PrinciRaj1992 */`

Output:

`2343`

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

2

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.
{"ft_lang_label":"__label__en","ft_lang_prob":0.653575,"math_prob":0.8535052,"size":4982,"snap":"2020-45-2020-50","text_gpt3_token_len":1365,"char_repetition_ratio":0.19244677,"word_repetition_ratio":0.2625139,"special_character_ratio":0.28462464,"punctuation_ratio":0.10621469,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99807185,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-10-28T03:41:44Z\",\"WARC-Record-ID\":\"<urn:uuid:233f4fc2-a930-45b5-8a86-921289826127>\",\"Content-Length\":\"130094\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:faac58a3-d847-4b7d-a8de-80fb93c978d2>\",\"WARC-Concurrent-To\":\"<urn:uuid:567728a4-0855-4423-b82f-fc00871bdd50>\",\"WARC-IP-Address\":\"23.215.132.186\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/how-to-concatenate-two-integer-values-into-one/?ref=leftbar-rightbar\",\"WARC-Payload-Digest\":\"sha1:2TPIWPY7Y4LPRVDWF565Y3FGVCTLLB2B\",\"WARC-Block-Digest\":\"sha1:RLTYGA72IJBLD6YGDW3UMV5EHUDJPDDH\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-45/CC-MAIN-2020-45_segments_1603107896048.53_warc_CC-MAIN-20201028014458-20201028044458-00532.warc.gz\"}"}