[C language] Change uppercase letters to lowercase letters, lowercase letters to uppercase letters, and other characters to output normally

Description: According to the ACSLL code, analyze the range of numbers corresponding to uppercase letters and lowercase letters, and the difference between uppercase and lowercase letters

The range of capital letters: 65--90 (A-65, Z-90)

The range of lowercase letters: 97--122 (a-97, z-122)

The difference between the corresponding uppercase and lowercase letters is 32

code show as below:

#include<stdio.h>
int main()
{
	char a;
	scanf_s("%c", &a);
	if (a >= 65 && a <= 90)
	{
		a=a + 32;
		printf("%c", a);
	}
	else if (a >= 97 && a <= 122)
	{
		a=a - 32;
		printf("%c", a);
	}
	else
	{
		printf("%c", a);
	}
	return 0;
	}

If the fifth line shows an error, you can remove the _s of scanf_s and change it to scanf

As a rookie who is new to C language, if there are any deficiencies in the code, please give me your advice.

Guess you like

Origin blog.csdn.net/weixin_73911965/article/details/128499458