zoukankan      html  css  js  c++  java
  • 计算三个数相加的和

    /* 心算训练(连加3个三位数的整数)*/
    
    #include <time.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
        int a, b, c;                /* 要进行加法运算的数值 */
        int x;                        /* 已读取的值 */
        clock_t start, end;            /* 开始时间·结束时间 */
        double req_time;            /* 所需时间 */
    
        srand(time(NULL));            /* 设定随机数的种子 */
    
        a = 100 + rand() % 900;        /* 生成100~999的随机数 */
        b = 100 + rand() % 900;        /**/
        c = 100 + rand() % 900;        /**/
    
        printf("%d + %d + %d等于多少:", a, b, c);
    
        start = clock();            /* 开始计算 */
    
        while (1) {
            scanf("%d", &x);
            if (x == a + b + c)
                break;
            printf("a回答错误!!
    请重新输入:");
        }
    
        end = clock();                /* 计算结束 */
    
        req_time = (double)(end - start) / CLOCKS_PER_SEC;
    
        printf("用时%.1f秒。
    ", req_time);
    
        if (req_time > 30.0)
            printf("花太长时间了。
    ");
        else if (req_time > 17.0)
            printf("还行吧。
    ");
        else
            printf("真快啊。
    ");
    
        return 0;
    }

    输出

    933 + 630 + 657等于多少:8989
    回答错误!!
    请重新输入:90879
    回答错误!!
    请重新输入:
  • 相关阅读:
    三、linux系统管理
    二、基本命令
    一、基本环境
    mysql-day4
    mysql-day3
    mysql-day2
    mysql-day1
    3、线性表的链式存储结构
    2、线性表之顺序表
    1、时间复杂度
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11037581.html
Copyright © 2011-2022 走看看