+ 2
Can you please explain me how this program works to convert Uppercase Character to Lowercase.
#include<iostream.h> #include<conio.h> void main() { clrscr(); char ch; cout<<"Enter a character in uppercase : "; cin>>ch; ch=ch+32; cout<<"character in lowercase = "<<ch; getch(); }
3 Antworten
+ 14
Each char and symbol has a predefined ascii value
Suppose you input A having ascii value of 65
ch adds 32 to it.. it gives value of 97
97 is the ascii value for a
Thus converting A to a and so on
You can refer Ascii table for more details
+ 5
The way to get a lowercase alphabet that way needs care actually, because if the user types in a character which is not within A-Z the result can be confusing, you should check first whether or not the character is between A-Z :)
+ 2
Actually, there is a easy way.
you should include <cctype>.
#include <cctype>
int main{
char ch;
cin>> ch;
ch = tolower(ch); //tolower() function converts uppercase to lowercase
ch = toupper(ch); //toupper() function converts lower to upper
}