0% found this document useful (0 votes)
2 views3 pages

Cse Lab CLS 2

The document contains multiple C++ programs demonstrating string manipulation techniques, including calculating substring length, checking for palindromes, and handling user input. It features examples of finding the length of a string, extracting substrings, and comparing original and reversed strings to determine if they are palindromes. Additionally, there are variations in the palindrome checking logic, including handling spaces in the input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Cse Lab CLS 2

The document contains multiple C++ programs demonstrating string manipulation techniques, including calculating substring length, checking for palindromes, and handling user input. It features examples of finding the length of a string, extracting substrings, and comparing original and reversed strings to determine if they are palindromes. Additionally, there are variations in the palindrome checking logic, including handling spaces in the input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SUB STRING LENGTH

#include<iostream>
#include<string>
using namespace std;
int main()
{
string s1= "Hello World";
int len = s1.length();

cout<<"Length: "<<len<<endl;
cout<<"Substring: "<<s1.substr(2,3)<<endl;
cout<<"W found at: "<<s1.find("W")<<endl;
}

Palindrome
#include <iostream>
#include<string>
using namespace std;

int main(){
char string1[20];
int i, length;
int flag = 0;

cout << "Enter a string: "; cin >> string1;

length = strlen(string1);

for(i=0;i < length ;i++){


if(string1[i]!= string1[length-i-1]){
flag = 1;
break;
}
}

if (flag) {
cout << string1 << " is not a palindrome" << endl;
}
else {
cout << string1 << " is a palindrome" << endl;
}
system("pause");
return 0;
}
Palindrome 2
#include <iostream>
#include<string>
using namespace std;

int main()
{

string s1,s2;
getline(cin,s1);
s2=s1;

int len=s1.length();

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


{
swap(s1[i],s1[len-i-1]);
cout<<s1<<endl;
}

if(s2==s1)
cout<<"True"<<endl;
else
cout<<"False"<<endl;
}
#include <iostream>
#include<string>
using namespace std;

int main()
{

string s1,s2;
getline(cin,s1);
s2=s1;

int len=s1.length();

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


{
if(s1[i]==' '|| s1[len-i-1]==' ');
{
continue;
}
swap(s1[i],s1[len-i-1]);

if(s2==s1)
cout<<"True"<<endl;
else
cout<<"False"<<endl;
}

*bhul thakte pare recheck kore likhio

You might also like