标签:计算 图片 sign 能力 i++ system win 基础上 技术分享
本次我在上次的四则运算的基础上加上了真分数运算,在之前的基础上改变一下运算代码
代码如下:
#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"); }
运行结果截图如下:
本次实验又是自己不错的一个学习经历,自己长了不少能力,有不小的收货,自己对于这门课程还要更加努力的学习,天天向上,同时希望自己能够学号这门课,自己对于计算机一直比较陌生,希望这次的锻炼能够加强自己对计算机的认识,同时提高自己的能力,强化自身
标签:计算 图片 sign 能力 i++ system win 基础上 技术分享
原文地址:https://www.cnblogs.com/chj139207/p/9768500.html