《c程序设计语言》-2.10 不用if-else 转换大小写

#include <stdio.h>


int lower(char a)
{
    int b;
    b = (a >= 'A' && a <= 'Z') ? (a - 'A' + 'a') : a;
    return b;
}

int main()
{
    int c;
    
    while((c = getchar()) != EOF && c != '
')
        putchar(lower(c));
        
    return 0;
}


比较简单。


下面两行实用,使程序更好看。


printf("%3d%c",c[i],(i % 10 == 9 || i == 99) ? '
' : ' ');

printf("You have %d item%s.
",n,n == 1 ? "" : "s");



原文地址:https://www.cnblogs.com/batteryhp/p/5020471.html