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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: