其实是赶作业的产物,做的十分粗糙,错漏也存在,但姑且算是完成了吧,下次不能到最后时间才行动了。
by c language
#include "stdafx.h"
#include "time.h"#include "stdlib.h"int randnum(int numlv)
{ int num; num = rand() % numlv; return num;}int randsym(int symly){ int sym; sym = rand() % symly+1; return sym;}int _tmain(int argc, _TCHAR* argv[]){ int a, b, s, nlv, slv,sym,num=0,rt=0,wr=0; srand(time(NULL)); printf_s("请输入数字上限\n"); scanf_s("%d", &nlv); printf_s("请输入算符等级(1.二则,2.四则)"); scanf_s("%d", &slv);while (num != -1)
{ a = randnum(nlv); sym = randsym(slv); b = randnum(nlv); if ((a - b) < 0 ) sym = 5; if (sym == 4) { if (b == 0) sym = 5; if (a / b != 0) sym = 5; } switch (sym) { case 1:s = a + b; printf_s("%d+%d=", a, b); break; case 2:s = a - b; printf_s("%d-%d=", a, b); break; case 3:s = a * b; printf_s("%d*%d=", a, b); break; case 4:s = a / b; printf_s("%d/%d=", a, b); break; default:break; } if (sym != 5) { scanf_s("%d", &num); if (num == s) { printf_s("right!\n"); rt++; } else { printf_s("wrong!\n"); wr++; } } } printf_s("总共做了%d个题,正确%d个,错误%d个",rt+wr-1,rt,wr -1); scanf_s("%d", &a); return 0;}程序不是重点,主要是学习使用GIT。