Answer to Question #20173 in C++ for apoorva

Question #20173
Write a program to reverse a string
(i)using another array
(ii)without another array
1
Expert's answer
2012-12-07T03:57:22-0500

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>

void main()
{

int str[50], rev[50];

cout<< "
Enter a string :";
gets(str);
int l = strlen(str);

/* Reverse String using another array */
for( int i = l-1, k = 0 ; i>= 0 ; i--, k++)
rev[k] = str[i];

cout<< "
Original String is "<< str;
cout<< "
Reverse String is "<< rev ;
cout<< "
Reverse String is ";

/* Reverse String without using another array */
for( i = l-1 ; i>=0 ; i--)
cout<< str[i];

getch();

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS