Print every character of a string twice

 Problem statement:- Program to Print every character of a string twice.

Example:-

              Input: Given

                                 String=csinfo

             Output: ccssiinnffoo

            Input: Given

                                String=csinfo360

             Output: ccssiinnffoo336600

Data requirement:-


   Input Data:- str

  Output Data:-
str

  Additional Data:- 
in, len

Program in C

Here is the source code of the C Program to Print every character of a string twice.

Code:

#include<stdio.h>
#include<string.h>
main()
{
    char str[100]={0};
    int in;
    printf("Enter your String:");
    gets(str);
     printf("New String is:");
     for(in=0;in<strlen(str);in++)
    {
           printf("%c%c",str[in],str[in]);
    }
}

Input/Output:
Enter your String:csinfo
New String is:ccssiinnffoo

Program in C++

Here is the source code of the C++ Program to Print every character of a string twice.

Code:

#include<iostream>
#include <cstring>
using namespace std;
main()
{
    string str;
    cout<<"Enter your String:";
    getline(cin,str);
    int len=0,in;
    for(in=0;str[in]!='\0';in++)
    {
        len++;b
    }
    cout<<"New String is:";
     for(in=0;in<len;in++)
    {
           cout<<str[in]<<str[in];
    }
}

Input/Output:
Enter your String:csinfo360
New String is:ccssiinnffoo336600

Program in Java

Here is the source code of the Java Program to Print every character of a string twice.

Code:

import java.util.Scanner;
public class EveryCharPrintTwice {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
String str;
int in;
System.out.println("Enter your String:");
str=cs.nextLine();
for(in=0;in<str.length();in++)
    {
System.out.print(str.charAt(in));
System.out.print(str.charAt(in));
    }
cs.close();
}
}

Input/Output:
Enter your String:
csinfo360.com
ccssiinnffoo336600..ccoomm

Program in Python

Here is the source code of the Python Program to Print every character of a string twice.

Code:

str=input("Enter Your String:")
for inn in range(0,len(str)):
    print(str[inn]+str[inn],end="")

Input/Output:
Enter Your String:python string question
ppyytthhoonn  ssttrriinngg  qquueessttiioonn

Post a Comment

0 Comments