标签:
设计思路:
1.定义随机数组a[30],b[30],e[30],f[30],定义真分数和整数算式判断符z,若z为0,则为真分数算术式,若z为1,则为整数算术式。
2.定义符号数组c[4],d为符号数组下标的随机数,有四种情况 + - * /
3.用循环输出30个表达式,通过判断z和符号,输出不同格式的表达式
4.若出现假分数,则不计算此次循环
1 #include<iostream> 2 #include<cmath> 3 #include<cstdlib> 4 using namespace std; 5 6 void main() 7 { 8 int a[30], b[30]; 9 char c[4]; 10 int d; 11 int e[30], f[30], z; 12 c[0] = ‘+‘; 13 c[1] = ‘-‘; 14 c[2] = ‘*‘; 15 c[3] = ‘/‘; 16 d = 0; 17 for (int i = 0; i < 30; i++) 18 { 19 a[i] = rand() % 10; 20 b[i] = rand() % 10; 21 e[i] = rand() % 10; 22 f[i] = rand() % 10; 23 z = rand() % 2; 24 if (z == 0) //判断是否是分数;0为真分数,1为整数 25 { 26 if (a[i] < b[i]) //真分数的编程循环 27 { 28 if (e[i] < f[i]) 29 { 30 d = rand() % 4; 31 cout << "第"<<i<<"题:" << a[i] << "/" << b[i] << c[d] << e[i] << "/" << f[i] << "="<<end 32 } 33 else 34 i = i - 1; 35 36 } 37 else 38 i = i - 1; 39 } 40 else //整数的编程 41 cout << "第"<<i<<"题:" << a[i] << c[d] << e[i] << "="<<endl; 42 } 43 system("pause"); 44 }
标签:
原文地址:http://www.cnblogs.com/zjy666/p/5247688.html