1.编程实现从键盘输入一个大写英文字母,分别以字符形式和ASCII码值形式输出其对应的小写英文字母.

1.编程实现从键盘输入一个大写英文字母,分别以字符形式和ASCII码值形式输出其对应的小写英文字母.
其他人气:544 ℃时间:2019-08-19 10:30:33
优质解答
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char c;

    scanf("%c", &c);
    if((c <= 'A') || (c >= 'Z'))
    {
        printf("非大写字母.\n");
    }
    else
    {
        c = c + 32;
        printf("%c %d\n", c, c);
    }

    return 0;
}如果是输入小写字母输出大写字母呢?

这个需要知道小写字母和大写字母在ASCII码的大小就行了


A  65   Z 90


a  97   z  116


大写转小写是+32,小写转大写-32就可以了

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    char c;
 
    scanf("%c", &c);
    if((c <= 'a') || (c >= 'z'))
    {
        printf("非大写字母。\n");
    }
    else
    {
        c = c - 32;
        printf("%c %d\n", c, c);
    }
 
    return 0;
}
我来回答
类似推荐
请使用1024x768 IE6.0或更高版本浏览器浏览本站点,以保证最佳阅读效果。本页提供作业小助手,一起搜作业以及作业好帮手最新版!
版权所有 CopyRight © 2012-2024 作业小助手 All Rights Reserved. 手机版