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.
Answers
Answered by
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;
}
#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; }
Answered by
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;
}
#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;
}
Similar questions
Math,
6 months ago
English,
6 months ago
Math,
1 year ago
Computer Science,
1 year ago
Social Sciences,
1 year ago