Program to concatenate a string

Program to concatenate a string

21 April 2023

21 April 2023

Write a Program to concatenate a string



If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023

Description

Get two strings as input from the user and then concatenate it.

 

Input

Enter first string

Hello

Enter second string

Hi

 

Output

HelloHi

 

 

C Program

#include<stdio.h>

#include<string.h>

int main()

{

    char str1[50];

    char str2[50];

    printf("Enter first string: ");

    scanf("%s",str1);

    printf("Enter second string: ");

    scanf("%s",str2);

    strcat(str1,str2);

    printf("Concatenated string: %s",str1);

    return 0;

}

 

C++ Program

#include<iostream>

#include<string.h>

using namespace std;

int main()

{

    char str1[50];

    char str2[50];

    cout<<"Enter first string: ";

    cin>>str1;

    cout<<"Enter second string: ";

    cin>>str2;

    strcat(str1,str2);

    cout<<"Concatenated string: "<<str1;

    return 0;

}

 

Java

import java.util.Scanner;

public class Main

{

              public static void main(String[] args) {

                  Scanner sc = new Scanner(System.in);

                             System.out.println("Enter first string: ");

                             String str1 = sc.nextLine();

                             System.out.println("Enter second string: ");

                             String str2 = sc.nextLine();

                             System.out.println("Concatenated string: "+(str1+str2));

              }

}

 

Python

str1=input("Enter first string: ")

str2=input("Enter second string: ")

print("Concatenated string: ",str1+str2)


If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023


Related Articles

Ask Us Anything !