Q.1 :write a program to reverse a string without using reverse method.please give an example of such a program.Q.2 :how can we concatenate two strings without using concatenate operatorplease give an example.

Questions by Ajit Kumar Maharatha

Showing Answers 1 - 2 of 2 Answers

#includ<iostream.h>
int main()
{
char name[80],name1[80];
int i,j;
cout<<"nEnter string to be reversed:";
cin.getline(name,80);
i=j=0;
while(name[i]!='')
i++;
while(--i>=0)
name1[j++]=name[i];
name1[j]='';
cout<<"nReversed string is "<<name1<<"n";
return 0;
}

  Was this answer useful?  Yes

#include<iostream.h>
int main()
{
char name[80],name1[80];
int i,j;
cout<<"nEnter string to be reversed:";
cin.getline(name,80);
i=j=0;
while(name[i]!='')
i++;
while(--i>=0)
name1[j++]=name[i];
name1[j]='';
cout<<"nReversed string is "<<name1<<"n";
return 0;
}


here first we calculate the length of the first string. the n last character of the first strin is  copied to the first character of the second string. here we are using one decrement operator to decrement the position of the first string, and one increment operator to increment the position of the second string

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions