小学二年级三十道四则运算题目-扩展运算,添加指定题目数量和支持真分数运算

代码:

#include<stdio.h>
  #include<Windows.h>
  #include<time.h>
  void main()
  {
      int a, b, c, d,i,m,n;
      float p, q;
      srand(unsigned( time(NULL)));
      for (i = 0; i < 30; i++)
  
   {
         a = rand() % 100;
         b = rand() % 100;
         c = rand() % 5;
         switch (c)
         {
        case 0: printf("%d + %d =\n", a, b);
             break;
         case 1:if (a < b)
         {
                    d = a;
                    a = b;
                    b = d;
         }
                printf("%d - %d =\n", a, b);
                break;
         case 2:printf("%d * %d =\n", a, b);
             break;
         case 3:
            while (b == 0)
             {
                 b = rand() % 100;
             }
             printf("%d / %d =\n", a, b);
             break;
         case 4:
             a = rand() % 100;
             b = rand() % 100;
             m = rand() % 100;
             n = rand() % 100;
             c = rand() %4 ;
             while (b == 0)
             {
                 b = rand() % 100;
             }
             while (n == 0)
             {
                 n = rand() % 100;
             }
             if (a > b)
             {
                 d = a;
                 a = b;
                 b = d;
             }
             if (m > n)
             {
                 d = m;
                 m = n;
                 n = d;
            }
             switch (c)
             {
             case 0:printf("%d/%d + %d/%d =\n", a, b, m, n);
                 break;
             case 1:
                 p = (float)a / (float)b;
                 q = (float)m / (float)n;
                 if (p < q)
                 {
                     d = a;
                     a = m;
                     m = d;
                     d = b;
                     b = n;
                     n = d;
                 }
                printf("%d/%d - %d/%d =\n", a,b,m,n);
                 break;
             case 2:printf("%d/%d * %d/%d =\n", a, b, m, n);
                 break;
             case 3:
                 a = rand() % 100;
                 b = rand() % 100;
                 m = rand() % 100;
                 n = rand() % 100;
                 c = rand() % 4;
                 while (m == 0)
                 {
                     m = rand() % 100;
                }
                 printf("%d/%d / %d/%d =\n", a, b, m, n);
                 break;
             }
         }
     }
     system("pause");
 }

结果:

原文地址:https://www.cnblogs.com/qingjia/p/9752058.html

时间: 2024-07-30 05:33:36

小学二年级三十道四则运算题目-扩展运算,添加指定题目数量和支持真分数运算的相关文章

小学二年级三十道四则运算题目。

代码: #include <stdio.h>#include <string.h>#include <stdlib.h>#include <time.h> int main(int argc, char **argv){    int a[30],b[30];     int i,c,d;        srand((unsigned int)time(NULL));    for (i = 0; i < 30; i++)    {          

随机产生三十道四则运算题程序

#include<stdio.h>#include<stdlib.h>#include<time.h>int main(){ int x,y,z,t,i; srand(time(NULL)); printf("三十道四则运算题\n"); for(i=0;i<30;i++) { x=rand()%100; y=rand()%100; z=rand()%4; switch(z) { case 0: printf("%d+%d=\n&quo

二年级四则运算的扩展,可以指定题目数量,并可支持真分数的运算

新加的要求: 1.可指定题目数量: 2.支持真分数运算. 代码编写: #include<stdio.h>  #include<Windows.h>  #include<time.h>  void main()  {      int a, b, c, d,i,m,n;      float p, q;      srand(unsigned( time(NULL)));      for (i = 0; i < 30; i++)      {         a 

二年级的30道四则运算题

想法思路:(1)在1-100之内产生两个随机数,并且随机的进行四则运算: (2)循环进行30次,产生30道题: (3)二年级时,没有学到分数和负数,减数要小于或等于被减数. 源程序代码: #include "stdafx.h" #include"iostream.h" #include"stdlib.h" #include"math.h"#include"time.h" int main(int argc,

随机给出三十道四则运算题目

这是课上练习,应用了随机函数,涉及是三个部分第一操作数.运算符.第二操作数,这三个部分都是随机产生的:第一.第二操作数可以应用随机函数产生符合条件的数值,运算符的产生可以在0-3,之间产生随机整数,分别代表一种运算符,即可完成要求. #include<iostream>using namespace std;void main(){ for(int x=0;x<30;x++) { int a=rand()%100; int b=rand()%100; int c=rand()%3; sw

关于三十道四则运算题的修改(修改减法,使其被减数大于减数)

#include "stdafx.h"#include<stdio.h>#include<stdlib.h>int main(int argc, char* argv[]){ int i,j,k,sum; for(int t = 0;t<30;t++) { i = rand()%50; j = rand()%50; k = rand()%4; switch(k) { case 0: sum = i+j; printf("第%d道题:",

一个可以自动生成三十道四则运算的程序

#include<stdio.h>int main() { int i,j,k,a; for(i=0;i<13;i++){ j=rand()%(99-10+1)+10; k=rand()%(99-10+1)+10; a=rand()%(4-1+1)+1;switch(a){case 1:printf("%d+%d=\n",j,k);case 2:printf("%d*%d=\n",j,k); case 3:printf("%d-%d=\n

简单小程序——产生三十道小学四则运算题目

题目要求程序可以生成三十道小学四则运算题目. 因为要随机生成题目,则需要产生随机数,因此我上网搜索了生成随机数的方法,选择了使用Random类得到规定范围内的随机数.因为一个运算需要三个元素,两个参与运算的数字,一个运算符(加减乘除),因此需要获得三个随机数,其中一个随机数的范围为1~4,对应加减乘除四个运算符.在程序中需要特别注意的是除法的运算题目生成,由于是小学题目,因此要生成可以整除的运算式.因此在除法的运算阶段,我进行了判断,若当前产生的两个随机数不能实现整除或者除数为零,便重新获得两个

30道小学二年级四则运算题

思路与体会:用rand函数产生随机数32767/327约等于100.2.排除了除数是0的错误, 但是仍有缺陷:减法会出现不够减结果是负数的情况! 运行结果总出现闪退情况,查阅资料后加了system("pause") 运行环境:vs2013 源代码: #include<iostream> using namespace std; #include<stdio.h> #include<stdlib.h>int rak(){ return rand() /