Software engineering class Practice-randomly generate 30 arithmetic exercises

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.