0% found this document useful (0 votes)
9 views

C++ Programs

Uploaded by

Oviya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

C++ Programs

Uploaded by

Oviya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program to reverse a string:

#include <cstring> // For using string functions

#include <iostream> // For I/O

using namespace std;

int revstr(char strr[]); // Corrected function signature

int main() {

char str[10];

cout << "Enter the string: ";

// Input the string

for(int i = 0; i < 9; i++) {

cin >> str[i];

// Reverse the string

revstr(str);

// Print the reversed string

cout << "The string reversed is: ";

for(int i = 0; i < 9; i++) {

cout << str[i];

return 0;

// Function to reverse the string

int revstr(char strr[]) {

int len = strlen(strr); // Find the length of the string


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

// Swap characters

swap(strr[i], strr[len - i - 1]);

return 0;

#include<iostream>

#include<cstring>

using namespace std;

2. to reverse a string

int main()

int arrsize;

cout<<"enter the len of the array size:";

cin>>arrsize;

char str1[arrsize];

cout<<"enter the string to be reversed:";

for(int i=0;i<arrsize;i++)

cin>>str1[i];

//to reverse the string using for loop

for(int i=arrsize;i>=0;i--)

cout<<str1[i];

You might also like