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

tayyab cs1

The program prompts the user to enter a string, reverses it, and checks if it is a palindrome. It then swaps the case of each character in the string and displays both the original and modified strings. The program utilizes standard input/output and string manipulation functions from the C++ standard library.

Uploaded by

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

tayyab cs1

The program prompts the user to enter a string, reverses it, and checks if it is a palindrome. It then swaps the case of each character in the string and displays both the original and modified strings. The program utilizes standard input/output and string manipulation functions from the C++ standard library.

Uploaded by

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

Program

#include <iostream>
#include <cstring> // for strlen()

int main() {

char str[100];

std::cout << "Enter a string: ";


std::cin.getline(str, 100);

int length = strlen(str);


for (int i = 0; i < length / 2; i++) {
char temp = str[i];
str[i] = str[length - i - 1];
str[length - i - 1] = temp;
}

int isPalindrome = 1; // Assume the string is a palindrome initially


for (int i = 0; i < length / 2; i++) {
if (str[i] != str[length - i - 1]) {
isPalindrome = 0; // Not a palindrome
break;
}
}

std::cout << "Reversed string: " << str << std::endl;


if (isPalindrome == 1) {
std::cout << "The string is a palindrome." << std::endl;
} else {
std::cout << "The string is not a palindrome." << std::endl;
}

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


if (isupper(str[i])) {
str[i] = tolower(str[i]);
} else if (islower(str[i])) {
str[i] = toupper(str[i]);
}
}

std::cout << "Original string: " << str << std::endl;


std::cout << "Modified string (swapped case): " << str << std::endl;

return 0;
}

You might also like