IN C++
Write a program named printStringReverse.cpp to read in a C-Style sting. Print the string forward and then backward using pointer increment and decrement. Declare the C-Style string as following: char s[50]; Read the string as follows; cin >> s; Write the following code to get the actual number of characters from your string. int count=0; while (s[count] != NULL) { count++; } count contains the actual length of your string since we declared the array to hold a limit of 50 characters.
Program :
#include <iostream>
using namespace std;
int main()
{
char s[50];
int count=0,i=0;
cin>>s;
while (s[count] != NULL)
{
count++;
}
cout<<"Print the string forward: ";
for(i=0;i<count;i++)
cout<<*(s+i);
cout<<"\nPrint the string backward: ";
for(i=count-1;i>=0;i--)
cout<<*(s+i);
return 0;
}
Screen shot of the program and output :
Get Answers For Free
Most questions answered within 1 hours.