Program to convert case of character
- Write a program to convert case of character in C
- Write a program to convert case of character in C++
- Write a program to convert case of character in Python
- Write a program to convert case of character in PHP
- Write a program to convert case of character in Java
- Write a program to convert case of character in Java Script
- Write a program to convert case of character in C#
Explanation:
You can utilize programming methods or built-in functions from many languages to change a character’s case. Converting case usually entails changing alphabetic characters from uppercase to lowercase.
- Uppercase to Lowercase:
- Add 32 to the ASCII value of a character.
- Lowercase to Uppercase:
- Subtract 32 from the ASCII value of a character.
Alternatively, use built-in functions for case conversion.
Program to convert case of character
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h> #include <ctype.h> // for toupper() and tolower() int main() { char ch = 'A'; // Change this to test other characters if (islower(ch)) { ch = toupper(ch); } else if (isupper(ch)) { ch = tolower(ch); } printf("Converted character: %c\n", ch); return 0; }
#include <iostream> #include <cctype> // for std::toupper and std::tolower int main() { char ch = 'A'; // Change this to test other characters if (std::islower(ch)) { ch = std::toupper(ch); } else if (std::isupper(ch)) { ch = std::tolower(ch); } std::cout << "Converted character: " << ch << std::endl; return 0; }
ch = 'A' # Change this to test other characters if ch.islower(): ch = ch.upper() elif ch.isupper(): ch = ch.lower() print(f"Converted character: {ch}")
<?php $ch = 'A'; // Change this to test other characters if (ctype_lower($ch)) { $ch = strtoupper($ch); } elseif (ctype_upper($ch)) { $ch = strtolower($ch); } echo "Converted character: $ch\n"; ?>
public class Main { public static void main(String[] args) { char ch = 'A'; // Change this to test other characters if (Character.isLowerCase(ch)) { ch = Character.toUpperCase(ch); } else if (Character.isUpperCase(ch)) { ch = Character.toLowerCase(ch); } System.out.println("Converted character: " + ch); } }
let ch = 'A'; // Change this to test other characters if (ch === ch.toLowerCase()) { ch = ch.toUpperCase(); } else if (ch === ch.toUpperCase()) { ch = ch.toLowerCase(); } console.log(`Converted character: ${ch}`);
using System; class Program { static void Main() { char ch = 'A'; // Change this to test other characters if (char.IsLower(ch)) { ch = char.ToUpper(ch); } else if (char.IsUpper(ch)) { ch = char.ToLower(ch); } Console.WriteLine($"Converted character: {ch}"); } }