标签:
#include <stdio.h> #include <stdlib.h> #include <time.h> int add(int num1,int num2) { return num1+num2; } int subtraction(int num1,int num2) { return num1-num2; } int mul(int num1,int num2) { return num1*num2; } float divis(int num1,int num2) { return ((int)(((float)num1/num2)*100+0.5))/100.0; } int main() { int type = -1; int data = -1; int choice,num1,num2,results; float div_result; char ch; int i,j,num3,num4; printf("请输入四则运算题目的数量:\n"); scanf("%d",&j); srand((unsigned int)time(NULL)); for(i=0;i<j;i++){ num3=rand()%100+1; num4=rand()%100+1; choice=rand()%8; switch (choice) { case 1: num1 = rand()%100+1; num2 = rand()%100+1; printf("%d+%d=\n",num1,num2); break; case 2: num1 = rand()%100+1; num2 = rand()%100+1; printf("%d-%d=\n",num1,num2); break; case 3: num1 = rand()%10; num2 = rand()%10; printf("%d*%d=\n",num1,num2); break; case 4: num1 = rand()%10; num2 = rand()%10+1; printf("%d/%d=\n",num1,num2); break; case 5: num1 = rand()%100+1; num2 = rand()%100+1; printf("%d/%d+%d/%d=\n",num1,num3,num2,num4); break; case 6: num1 = rand()%100+1; num2 = rand()%100+1; printf("%d/%d-%d/%d=\n",num1,num3,num2,num4); break; case 7: num1 = rand()%10; num2 = rand()%10; printf("%d/%d*%d/%d=\n",num1,num3,num2,num4); break; case 8: num1 = rand()%10; num2 = rand()%10+1; printf("%d/%d/%d/%d=\n",num1,num3,num2,num4); break; } } }
1. 编写一个能自动生成小学四则运算题目的程序。
总结:老师和同学们都说这次作业特别简单,但是在做的过程中,我还是遇到了很多问题。说明c语言的基础还有待提高,在接下来的时间要加强学习。
标签:
原文地址:http://www.cnblogs.com/lylljj/p/5280740.html