Advertisements
Advertisements
प्रश्न
Write a C++ program to accept a sentence (maximum 50 characters) and print the sentence in reverse.
थोडक्यात उत्तर
उत्तर
//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;
}
shaalaa.com
C++ Programming
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?