• toupper函数及一些小程序


     1     
     2 
     3 toupper
     4     
     5 
     6   原型:extern int toupper(int c);
     7   
     8   用法:#include <ctype.h>
     9   
    10   功能:将字符c转换为大写英文字母
    11   
    12   说明:如果c为小写英文字母,则返回对应的大写字母;否则返回原来的值。
    13   
    14   举例:
    15 
    16 
    17       // toupper.c
    18       
    19       #include <syslib.h>
    20       #include <ctype.h>
    21 
    22       main()
    23       {
    24         char *s="Hello, World!";
    25         int i;
    26         
    27         clrscr();        // clear screen
    28         printf("%s
    ",s);
    29         for(i=0;i<strlen(s);i++)
    30         {
    31           putchar(toupper(s[i]));
    32         }
    33         
    34         getchar();
    35         return 0;
    36       }
    //---------------------------------1
    #include <stdio.h>
    #include<stdlib.h>
    void main()
    {
        printf("0 & 0 is %d
    ", 0 & 0);
        printf("0 & 1 is %d
    ", 0 & 1);
        printf("1 & 1 is %d
    ", 1 & 1);
        printf("1 & 2 is %d
    ", 1 & 2);
        printf("15 & 127 is %d
    ", 15 & 127);
        system("pause");
    }
    //------------------------------2
    #include <stdio.h>
    #include<stdlib.h>
    void main()
    {
        int value = 0xFF;
    
        printf("The inverse of %X is %X
    ", value, ~value);
        system("pause");
    }
    //-------------------------------3
    #include <stdio.h>
    #include<stdlib.h>
    void main()
    {
        printf("0 | 0 is %d
    ", 0 | 0);
        printf("0 | 1 is %d
    ", 0 | 1);
        printf("1 | 1 is %d
    ", 1 | 1);
        printf("1 | 2 is %d
    ", 1 | 2);
        printf("128 | 127 is %d
    ", 128 | 127);
        system("pause");
    }
    //------------------------------------4
    #include <stdio.h>
    #include<stdlib.h>
    void main()
    {
        printf("0 ^ 0 is %d
    ", 0 ^ 0);
        printf("0 ^ 1 is %d
    ", 0 ^ 1);
        printf("1 ^ 1 is %d
    ", 1 ^ 1);
        printf("1 ^ 2 is %d
    ", 1 ^ 2);
        printf("15 ^ 127 is %d
    ", 15 ^ 127);
        system("pause");
    }
    //------------------------------------5
    #include <stdio.h>
    #include<stdlib.h>
    void main()
    {
        printf("The letter is %c
    ", 'A');
        printf("The letter is %c
    ", 65);
        system("pause");
    }
    //---------------------------------------6
    #include <stdio.h>
    #include<stdlib.h>
    void main()
    {
        char letter;
    
        int vowel_count = 0;
        int consonant_count = 0;
    
        for (letter = 'A'; letter <= 'Z'; letter++)
            switch (letter) {
            case 'A':
            case 'E':
            case 'I':
            case 'O':
            case 'U': vowel_count++;
                break;
            default: consonant_count++;
        };
    
        printf("The number of vowels is %d
    ", vowel_count);
        printf("The number of vowels is %d
    ", consonant_count);
        system("pause");
    }
    //------------------------------------------------------------7
    #include <stdio.h>
    #include <conio.h>
    #include <ctype.h>
    #include <stdlib.h>
    
    void main()
    {
        char letter;
    
        do {
            printf("A Display directory listing
    ");
            printf("B Display disk information
    ");
            printf("C Change system date
    ");
            printf("Q Quit
    ");
            printf("Choice: ");
    
            letter = getchar();
            letter = toupper(letter);
    
            if (letter == 'A')
                system("DIR");
            else if (letter == 'B')
                system("CHKDSK");//不能用
            else if (letter == 'C')
                system("DATE");
        } while (letter != 'Q');
        system("pause");
    }
  • 相关阅读:
    【博客申明】
    OAF客制化代码导出页面数据到Excel文件
    OAF调用JS代码
    Java冒泡排序
    Java二分查找代码
    Java 在某一个时间点定时执行任务(转载)
    Oracle 常用SQL
    Oracle数据字典
    spring3.0事务管理配置
    由override 和 overload 引发的学习感悟
  • 原文地址:https://www.cnblogs.com/Zblogs/p/3355447.html
Copyright © 2020-2023  润新知