Wednesday, May 16, 2012

if else statement: uppercase to lowercase char/lowercase to uppercase char

Hello Guys!!! How are you? Hope, you all are well by the grace of Almighty. Today we do a c programming code about uppercase-lowercase conversion. Let's look at the problem.

Problem: Input a character. If the character is between "A"-"Z" convert to small letter. If the character is between "a"-"z" convert to capital letter.

Solve:




















We know that, the ASCII value of "a" is 97 and "z" is 122. In the first condition, this is applied. We also know that, the ASCII value of "A" is 65 and "Z" is 90. In the second condition this is applied.

We can also do this program by the following way:























The difference between any ASCII value of lowercase and uppercase character is 32. In this program, this is used. In line 12 and 17 "x-=32" & "x+=32" means "x=x-32" & "x = x + 32".

We can also do this program by the following way:



















In this program, "ctype.h" header file is used. toupper and tolower are library functions. toupper function converts any character into uppercase character & tolower converts any character into lowercase character.

Thnak you all..:)

0 comments:

Post a Comment