Computer Science, asked by AdishaDeo, 1 year ago

Write a program to reverse a string in c


mebijay: I can do it in C++ and Java. I am not sure if i can help.
AdishaDeo: Let it be do in c++

Answers

Answered by mebijay
2

#include <bits/stdc++.h>  

using namespace std;  

 


// Function to reverse a string  

void reverseStr(string& str)  

{  

   int n = str.length();  

 


   // Swap character starting from two  

   // corners  

   for (int i = 0; i < n / 2; i++)  

       swap(str[i], str[n - i - 1]);  

}  

 


// Driver program  

int main()  

{  

   string str = "sampleString";  

   reverseStr(str);  

   cout << str;  

   return 0;  

}


AdishaDeo: Much jyada complex ho gaya
AdishaDeo: But don't mind
barathbarclays100: hey tell in English
barathbarclays100: dimensional array.
#include int main(){ /* 2D array declaration*/ int disp[2][3]; /*Counter variables for the loop*/ int i, j; for(i=0; i<2; i++) { for(j=0;j<3;j++) { printf("Enter value for disp[%d][%d]:", i, j); scanf("%d", &disp[i][j]); } } //Displaying array elements printf("Two Dimensional array elements:\n"); for(i=0; i<2; i++) { for(j=0;j<3;j++) { printf("%d ", disp[i][j]); if(j==2){ printf("\n"); } } } return 0; }
AdishaDeo: Its a little complicated.
AdishaDeo: Don't mind
AdishaDeo: Don't u know Hindi?
barathbarclays100: i don't know hindi
AdishaDeo: Ok
AdishaDeo: Pls dont mind
Answered by barathbarclays100
1
#include <stdio.h>

#include <string.h>

 

int main()

{

   char arr[100];

 

   printf("Enter a string to reverse\n");

   gets(arr);

 

   strrev(arr);

 

   printf("Reverse of the string is \n%s\n", arr);

 

   return 0;

}


AdishaDeo: No but of which class are u
barathbarclays100: i am a college student
AdishaDeo: Don't worry I know u r fearing about ur personal data to be known by a stranger. I have felt this too hut then I thought anti social do not have interest in studies and by the way remember we were chatting one day in brainly
barathbarclays100: yes we one day chat in brainly
AdishaDeo: Then don't fear. I am like ur sister. I read in class 8
AdishaDeo: Are u from Tamil Nadu?????
AdishaDeo: I remember u said this to me
barathbarclays100: ok
barathbarclays100: yes i am from Tamil Nadu
barathbarclays100: hi adisha
Similar questions