Object
Write a program to input a character. If this character is in uppercase then convert it into lowercase and vice versa (without using toupper/tolower or isupper/islower functions).
Algorithm
- Declare integer variable a and character variable c.
- Read the character c.
- Set a = c (i.e., convert character into integer).
- IF (a >= 65 && a <= 90), then
- a = a + 32.
- Write the character a.
- ELSE
- a = a – 32.
- Write the character a.
- [End of IF-ELSE structure.]
- Exit.
Flowchart

C++ Source Code
// program 22a
#include <iostream>
using namespace std;
int main()
{
int a;
char c;
cout << "Enter a character: ";
cin >> c;
a = c;
if (a >= 65 && a <= 90)
{
a = a + 32;
cout << "The other case is " << static_cast<char>(a);
}
else
{
a = a - 32;
cout << "The other case is " << static_cast<char>(a);
}
return 0;
}
Object (second method)
Write a program to input a character. If this character is in uppercase then convert it into lowercase and vice versa.
C++ Source Code
// program 22b
#include <iostream>
using namespace std;
int main()
{
char c;
cout << "Enter a character: ";
cin >> c;
if (isupper(c))
{
c = tolower(c);
cout << "The other case is " << c;
}
else if (islower(c))
{
c = toupper(c);
cout << "The other case is " << c;
}
else
{
cout << "Invalid input! It's not an alphabet.";
}
return 0;
}
C Source Code
/*program 22*/
#include<stdio.h>
int main()
{
int a;
char c;
printf("Enter a character: ");
scanf("%c", &c);
a=c;
if(a>=65 && a<=90)
{
a=a+32;
printf("The other case is %c", a);
}
else
{
a=a-32;
printf("The other case is %c", a);
}
return 0;
}
Output
Enter a character: p
The other case is P
