zoukankan      html  css  js  c++  java
  • C语言 百炼成钢11

    //题目31:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续
    //判断第二个字母。
    
    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    
    //分析:通过输入的字母判定星期几,可以使用if()else
    
    void main(){
        char str[7] = { 0 };
        scanf("%s",str);
        switch ((int)str[0])
        {
        case 102:
            //f
            printf("
    今天是星期五");
            break;
        case 109:
            //m
            printf("
    今天是星期一");
            break;
        case 115:
            //s
            if (str[1]==97)
            {
                printf("
    今天是星期六");
            }
            else{
                printf("
    今天是星期日");
            }
            break;
        case 116:
            //t
            if (str[2] == 101)
            {
                printf("
    今天是星期二");
            }
            else{
                printf("
    今天是星期四");
            }
            break;
        case 119:
            //w
            printf("
    今天是星期三");
            break;
        default:
            break;
        }
        system("pause");
    }

    //题目32:Press any key to change color, do you want to try it. Please hurry up!
    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>
    #include<time.h>
    #include<Windows.h>
    
    //分析:cmd指令color的值有2个十六进制构成,范围是0-f,Press any key说明按下任意键变色,借助getchar()函数,
    //函数名:kbhit()功能及返回值: 检查当前是否有键盘输入,若有则返回一个非0值,否则返回0;用 法:int _kbhit(void);其头文件是conio.h
    
    
    void main(){
        //定义时间类型
        time_t ts;
        //定义随机数种子
        srand((unsigned int)time(&ts));
        //定义cmd中color的值
        char strcolor[30] = { 0 };
        while (1){
            getchar();
            sprintf(strcolor, "color %x%x", (int)(rand() % 16), (int)(rand() % 16));
            system(strcolor);
            
        }
        system("pause");
    }

    //题目33:求100之内的素数 
    
    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    //分析:写一个函数,判断该数是否是素数
    
    int sushu(int num){
        int temp = (int)sqrt(num + 1);
        for (int i = 2; i <= temp; i++)
        {
            if (num%i==0)
            {
                return 0;
            }
        }
        return 1;
    }
    
    void main(){
        for (int i = 0; i < 100; i++)
        {
            if (i==0||i==1||i==2||i==3)
            {
                printf("%d
    ", i);
            }
            else{
                if (sushu(i))
                {
                    printf("%d
    ", i);
                }
            }
        }
        system("pause");
    }

  • 相关阅读:
    links[v1]
    WebSocket handshake: Unexpected response code: 404
    Spring mvc 启动 和 请求分发
    匹配括号
    js parseFloat 精度问题
    遍历查找跳格子逻辑
    Generic type test java
    java高效判断素数
    从数组中取3个数全排列
    vue-cli
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/5152685.html
Copyright © 2011-2022 走看看