Reverse a Character in C++ using Library Function
ADVERTISEMENTS
Reverse a character in C++ using library function. In this article, you will learn how to reverse a character in c++ using library function.
Example-1
'b' after conversion 'B'
Example-2
'B' after conversion 'b'
You should have knowledge of the following topics in c++ programming to understand this program:
- C Cctype library
- C
main()
function - C
if-else
condition statement - C
cin
object - C
cout
object
Source Code
// Reverse a Character in C++ using Library Function
#include <iostream>
#include <cctype>
using namespace std;
// cctype header file loaded to call the string functions
int main() {
char random_char;
cout << "Enter an alphabet character to convert: ";
cin >> random_char;
cout << "\nThe Reverse case of the '" << random_char << "' is: '";
if (islower(random_char))
putchar(toupper(random_char));
else
putchar(tolower(random_char));
cout << "'\n";
return 0;
}
Output
Enter an alphabet character to convert: B
The Reverse case of the 'B' is: 'b'
Explanation
In this given program, we have taken input B
from the user and applied the function to convert the input's reverse case.