C Program to Convert String Lowercase to Uppercase And Vice Versa: Convert uppercase to lowercase and vice versa is a program to convert the case of each letter that is upper to lower and vice versa.

What is the upper case: letters A – Z are upper.
What is lowercase: letters a – z is lower.
In c , the ascii value of letters :
A = 65 , B = 66 , ….. , Z = 90.
a = 97 , b = 98 , …… , z = 122.
We can use the ASCII values of the letter based on that we convert upper case to lower case and vice versa.

To convert upper to lower: add 32 with an uppercase letter.
Example:
convert A to a
=> A + 32
=> 65 + 32
=> 97
And 97 is ascii value of a

The logic to convert lower to upper: subtract 32 with lower case letter.
Example:
convert a to A
=> a – 32
=> 97 – 32
=> 65
And 65 is ascii value of A

Page Contents

## Algorithm to convert String Lowercase to Uppercase And Vice Versa

1. Take the input string from the user.
2. Find the length of the string
3. Traverse string character one by one till the length of string
If the letter is upper
New-string= letter + 32
If the letter is lower,
New-string= letter – 32
If String reached at the end
Break
4. Print a new string.

## C Program to Convert String Lowercase to Uppercase And Vice Versa

```#include<stdio.h>
#include<string.h>

void main()
{
while(1)
{
char str;
int i;

printf("\n\nEnter The String: ");
scanf("%s",str);

for (i=0;i<=strlen(str);i++)
{
if (str[i]>=65&&str[i]<=90)
{
str[i] = str[i] + 32;
}

else if (str[i] >= 97 && str[i] <= 122)
{
str[i] = str[i] - 32;
}
}

printf("\n\nConvert String(Lower/Upper) Is: %s\n\n",str);
}

return 0;
}```

Output : 