Problem statement:- Program to Print a string using an array.
Data requirement:-
Input Data:- arr
Output Data:-arr
Output Data:-arr
Additional Data:- i, len
Program in C
Here is the source code of the C Program to Print a string using an array.
Code:
#include<stdio.h>
#include<string.h>
int main()
{
char arr[]="csinfo360.com";
int i=0;
int len=strlen(arr);//Calculating size of the string
while(i<len)
{
printf("%c",arr[i]);
i++;
}
}
#include<string.h>
int main()
{
char arr[]="csinfo360.com";
int i=0;
int len=strlen(arr);//Calculating size of the string
while(i<len)
{
printf("%c",arr[i]);
i++;
}
}
Input/Output:
csinfo360.com
Program in C++
Here is the source code of the C++ Program to Print a string using an array.
Code:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char arr[]="csinfo360.com";
int i=0;
int len=strlen(arr);//Calculating size of the string
while(i<len)
{
cout<<arr[i];
i++;
}
}
#include<cstring>
using namespace std;
int main()
{
char arr[]="csinfo360.com";
int i=0;
int len=strlen(arr);//Calculating size of the string
while(i<len)
{
cout<<arr[i];
i++;
}
}
Input/Output:
csinfo360.com
Program in Java
Here is the source code of the Java Program to Print a string using an array.
Code:
import java.util.Scanner;
public class p3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
char arr[ ]={'c','s','i','n','f','o','3','6','0','.','c','o','m'};
int i=0;
int len=arr.length;//Calculating size of the string
while(i<len)
{
System.out.print(arr[i]);
i++;
}
sc.close();
}
}
public class p3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
char arr[ ]={'c','s','i','n','f','o','3','6','0','.','c','o','m'};
int i=0;
int len=arr.length;//Calculating size of the string
while(i<len)
{
System.out.print(arr[i]);
i++;
}
sc.close();
}
}
Input/Output:
csinfo360.com
Program in Python
Here is the source code of the Python Program to Print a string using an array.
Code:
import array
arr=array.array('u', ['c','s','i','n','f','o','3','6','0','.','c','o','m'])
len=len(arr)
for i in range(0,len):
print(arr[i],end="")
arr=array.array('u', ['c','s','i','n','f','o','3','6','0','.','c','o','m'])
len=len(arr)
for i in range(0,len):
print(arr[i],end="")
Input/Output:
csinfo360.com
0 Comments
Please do not Enter any spam link in the comment box