0% found this document useful (0 votes)
9 views2 pages

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 views2 pages

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy