Advertisement Remove all ads

Write a C++ Program to Accept a Sentence (Maximum 50 Characters) and Print the Sentence in Reverse - Computer Science 1

Answer in Brief

Write a C++ program to accept a sentence (maximum 50 characters) and print the sentence in reverse.

Advertisement Remove all ads

Solution

 //Reverse a string
#include
void main ( )
{
char str [50], reverse [50];
int len, i, k;
cout << “Enter a string :” <<endl;
cin>>str;
for (i = 0; str [i]! = ‘\0’ ; i++)
len = i;
len - -;
for (k = 0; len >=0; len - -, k++)
reverse [k] = str [len];
reverse [k] = ‘\0’;
cout <<“reverse string is :”;
cout <<reverse;

Concept: C++ Programming
  Is there an error in this question or solution?
Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads
Share
Notifications

View all notifications


      Forgot password?
View in app×