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

String Manipulation and Palindrome Check

The document contains two C++ programs that perform string manipulations. The first program reverses a string and checks if it is a palindrome, while the second program demonstrates built-in string functions such as length calculation, copying, and concatenation. Both programs prompt the user for input and display the results of their operations.

Uploaded by

25ec052
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)
3 views2 pages

String Manipulation and Palindrome Check

The document contains two C++ programs that perform string manipulations. The first program reverses a string and checks if it is a palindrome, while the second program demonstrates built-in string functions such as length calculation, copying, and concatenation. Both programs prompt the user for input and display the results of their operations.

Uploaded by

25ec052
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

1) To find the length of the string, Reverse a given string and check

palindrome or not.

#include <iostream>
#include <cstring>
using namespace std;
int main(){
char s1[20], s2[20];
int n;
cout<<"Enter a string: ";
[Link](s1,20);
n=strlen(s1);
cout<<"Reversed string: ";
for(int i=0;i<n/2;i++)
swap(s1[i],s1[n-i-1]);
cout<<s1<<endl;
if (strcmp(s1,s2)==0)
cout<<"The given string is palindrome"<<endl;
else
cout<<"The given string is not palindrome"<<endl;
}

Output:
Enter a string: hello
Reversed string: olleh
The given string is not palindrome

2) String Manipulation(Built in Function)


#include <iostream>
#include <cstring>
using namespace std;
int main(){
char s1[20], s2[20];
int n;
cout<<"Enter a string: ";
[Link](s1,20);
n=strlen(s1);
cout<<"length of string"<<strlen(s1)<<endl;
strcpy(s2,s1);
cout<<"Copied string is"<<s2<<endl;
strcat(s2,s1); //concatenation of two strings
cout<<"Concatenation of s1 and s2"<<s2<<endl;
cout<<"Reversed string: ";
for(int i=0;i<n/2;i++)
swap(s1[i],s1[n-i-1]);
cout<<s1<<endl;
return 0;
}

Output:
Enter a string: madam
length of string5
Copied string ismadam
Concatenation of s1 and s2madammadam
Reversed string: madam

You might also like