Write a C++ Program to print a string on the screen entered by the user.
Program Code:
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
char str[50];
cout<<"Enter your city to visit : ";
gets(str);
cout<<"Welcome to, "<<str;
return 0;
}
The program is tested on www.jdoodle.com
Output:
Enter your city to visit : New Delhi.
Welcome to, New Delhi
Write a C++ program to find length of the string entered by the user.
Program Code:
#include<iostream>
#include<string.h>
int main()
{
char str[20];
int length;
cout<<"Enter a string to find its length : ";
gets(str);
length = strlen(str);
cout<<"Length of the given string is : "<<length;
return 0;
}
The program is tested on www.jdoodle.com
Output:
Enter a string to find its length : New Delhi India.
Length of the given string is : 16
//( dot (.) and space are also considered as an element)
Thanks
Mukesh Rajput
Post A Comment:
0 comments: