Problem statement:- Program to Input a string through the keyboard and Print the same.
Data requirement:-
Input Data:- arr
Output Data:-arr
Output Data:-arr
Additional Data:- i, size, temp
Program in C
Here is the source code of the C Program to Input a string through the keyboard and Print the same.
Code:
#include<stdio.h>
int main()
{
int size,i=0;
printf("Enter the size of the array:");
scanf("%d",&size);
char arr[size];
char temp;
scanf("%c",&temp);// it's clear the buffer
printf("Enter the String:");
scanf("%[^\n]",arr);
while(arr[i]!='\0')
{
printf("%c",arr[i]);
i++;
}
}
int main()
{
int size,i=0;
printf("Enter the size of the array:");
scanf("%d",&size);
char arr[size];
char temp;
scanf("%c",&temp);// it's clear the buffer
printf("Enter the String:");
scanf("%[^\n]",arr);
while(arr[i]!='\0')
{
printf("%c",arr[i]);
i++;
}
}
Input/Output:
Enter the size of the array:10
Enter the String:cs info
cs info
Enter the String:cs info
cs info
Program in C++
Here is the source code of the C++ Program to Input a string through the keyboard and Print the same.
Code:
#include<iostream>
using namespace std;
int main()
{
int size,i=0,j;
char arr[50];
cout<<"Enter the String:";
cin.get(arr,50);
while(arr[i]!='\0')
{
cout<<arr[i];
i++;
}
}
using namespace std;
int main()
{
int size,i=0,j;
char arr[50];
cout<<"Enter the String:";
cin.get(arr,50);
while(arr[i]!='\0')
{
cout<<arr[i];
i++;
}
}
Input/Output:
Enter the String:info 360
info 360
info 360
Program in Java
Here is the source code of the Java Program to Input a string through the keyboard and Print the same.
Code:
import java.util.Scanner;
public class p4 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int size,i=0,j;
System.out.println("Enter the size of the array:");
size=sc.nextInt();
char arr[]=new char[size];
System.out.println("Enter the String:");
for(j=0;j<size;j++){
char c=sc.next().charAt(0);
arr[j]=c;
}
while(i<size)
{
System.out.print(arr[i]);
i++;
}
sc.close();
}
}
public class p4 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int size,i=0,j;
System.out.println("Enter the size of the array:");
size=sc.nextInt();
char arr[]=new char[size];
System.out.println("Enter the String:");
for(j=0;j<size;j++){
char c=sc.next().charAt(0);
arr[j]=c;
}
while(i<size)
{
System.out.print(arr[i]);
i++;
}
sc.close();
}
}
Input/Output:
Enter the size of the array:
12
Enter the String:
C
o
r
o
n
a
v
i
r
u
s
-
Coronavirus-
12
Enter the String:
C
o
r
o
n
a
v
i
r
u
s
-
Coronavirus-
Program in Python
Here is the source code of the Python Program to Input a string through the keyboard and Print the same.
Code:
arr=[]
size = int(input("Enter the size of the array: "))
for i in range(0,size):
word = (input())
arr.append(word)
for i in range(0,size):
print(arr[i],end="")
size = int(input("Enter the size of the array: "))
for i in range(0,size):
word = (input())
arr.append(word)
for i in range(0,size):
print(arr[i],end="")
Input/Output:
Enter the size of the array: 9
C
O
V
I
D
-
1
9
CVOVID-19
C
O
V
I
D
-
1
9
CVOVID-19
0 Comments
Please do not Enter any spam link in the comment box