真分数四则
Posted lzm-000
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了真分数四则相关的知识,希望对你有一定的参考价值。
#include<stdio.h> #include<Windows.h> #include<time.h> void main() { int a, b, c, d,i,e,n; float p, q; srand(unsigned( time(NULL))); for (i = 0; i < 30; i++) { a = rand() % 100; b = rand() % 100; e = 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=d; d=b; } if (c>d) { d=c; c=d; d=b; } switch (c) { case 0:printf("%d/%d + %d/%d = ", a, b, e, n); break; case 1: p = a / b; q = e / n; if (p < q) { d = a; a = e; e = d; d = b; b = n; n = d; } printf("%d/%d - %d/%d = ", a,b,e,n); break; case 2:printf("%d/%d * %d/%d = ", a, b, e, n); break; case 3: a = rand() % 100; b = rand() % 100; e = rand() % 100; n = rand() % 100; c = rand() % 4; while (e == 0) { e = rand() % 100; } printf("%d/%d / %d/%d = ", a, b, e, n); break; } } system("pause"); }
以上是关于真分数四则的主要内容,如果未能解决你的问题,请参考以下文章