zoukankan      html  css  js  c++  java
  • 自动生成四则运算器

    这个项目是采用c语言实现的一个能根据用户要求数目自动生成相应的简单四则运算。

    代码如下:

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <math.h>

    int main()
    {
    int i=0;
    int a=0;
    int b=0;
    int type;
    char flag;
    int left, right;
    float result;
    printf("请输入要出的题目数量 ");
    scanf("%d",&a);
    srand(unsigned(time(NULL)));
    while(b<a)
    {
    type = rand() % 4;
    left = rand() % 100;
    right = rand() % 100;
    switch(type)
    {
    case 0:
    printf("%d + %d = ? ", left, right);
    break;
    case 1:
    printf("%d - %d = ? ", left, right);
    break;
    case 2:
    printf("%d * %d = ? ", left, right);
    break;
    case 3:
    printf("%d / %d = ? ", left, right);
    break;
    }

    i++;
    while(i>=a)
    {
    printf("一共 %d 题 ",i);
    printf("继续?[Y/N] ");
    fflush(stdin);
    scanf("%c",&flag);
    if(flag=='Y'||flag=='y')
    {
    printf("请输入要出的题目数量 ");
    scanf("%d",&a);
    i=0;
    break;
    }
    fflush(stdin);
    getchar();
    return 0;
    }
    }
    }

  • 相关阅读:
    SVN服务器搭建和使用(一)
    SVN服务器搭建和使用(一)
    lua loadstring与loadfile
    lua loadstring与loadfile
    lua_getstack
    lua_getstack
    让程序在崩溃时体面的退出之Dump文件
    bzoj1054
    poj3678
    poj2749
  • 原文地址:https://www.cnblogs.com/dbnbw/p/7593916.html
Copyright © 2011-2022 走看看