输入一个小写字母输出一个对应的大写字母

来源:互联网 发布:畅易阁淘宝 编辑:程序博客网 时间:2024/05/06 14:55
#include<stdio.h>int main(){    int one;    int two;    printf("please enter one char:\n");    one = getchar();    two = one - 32;    putchar(two);    printf("%c\n",two);    putchar('\n');    return 0;}

小写字母的ascii码值比大写字母大32;

但是我这台电脑的ascii码查出来只有1~127,开始时错把减号写成加号,导致输出的结果是该数的八进制(输入a,输出201这是八进制的129)

#include<stdio.h>int main(){    int one;    int two = 0;    printf("please enter one char:\n");    one = getchar();    while(one != EOF)    {        if(one >='a'&& one <= 'z')            two = one - 32;        putchar(two);        one = getchar();    }    return 0;}

这个更优化哩!可以输出一整串,上面那个只可以输入一个

0 0
原创粉丝点击