Exercise request: Randomly generate 30 arithmetic questions
Here is the program code:
1#include"stdafx.h"2#include"stdio.h"3#include"time.h"4#include"stdlib.h" //with machine function header file5 6 voidprint ()7 {8Srand ((int) Time (0));9 for(intI=0; i<= in; i++)Ten { One intx; A intA=rand ()% -; - intB=rand ()% -; - thex=1+rand ()%4;//randomly produce four different algorithms - Switch(x) - { - Case 1: {printf ("%d+%d=\t\t", A, b); Break;} + Case 2: {printf ("%d-%d=\t\t", A, b); Break;} - Case 3: {printf ("%d*%d=\t\t", A, b); Break;} + Case 4: { A if(a!=0) atprintf"%d/%d=\t\t", A, b); - Else - { -a=a+1; -printf"%d/%d=\t\t", A, b); - } in Break; - } to default:{"wrong output! ";} + } - } the } * intMainintargcChar*argv[]) $ {Panax Notoginseng print (); - return 0; the}
View Code
Design ideas:
In fact, the code is very simple, mainly to solve the problem of how to randomly generate numbers and how the numbers produced are randomly arithmetic these two problems. Because the code is simple, the specific idea has been reflected in the code through annotations.
Here's the result.
This class practice is not able to finish in class in time because of the unfamiliar programming and a lot of things are forgotten, can not think of random functions, programming this thing or more to knock more practice can.
Software engineering class Practice-randomly generate 30 arithmetic exercises