設計四則運算包含真分數的小學二年級運算
阿新 • • 發佈:2018-10-10
希望 unsigned clas color n) spa clu span break
本次我在上次的四則運算的基礎上加上了真分數運算,在之前的基礎上改變一下運算代碼
代碼如下:
#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"); }
運行結果截圖如下:
本次實驗又是自己不錯的一個學習經歷,自己長了不少能力,有不小的收貨,自己對於這門課程還要更加努力的學習,天天向上,同時希望自己能夠學號這門課,自己對於計算機一直比較陌生,希望這次的鍛煉能夠加強自己對計算機的認識,同時提高自己的能力,強化自身
設計四則運算包含真分數的小學二年級運算