软件工程概论之作业1,二柱子的逆袭

问题:

某家软件公司的程序员二柱家小孩上了小学二年级,老师让家长每天出30到四则运算题目给小学生做。二柱子利用了自己编程的知识来解决这个问题。

我选择了matlab来处理这个问题

代码:

A=randi([1 4],30,1);
disp ('请开始答题');
for i=1:30
  switch (A(i))
      case (1)
         fprintf('%d+%d\n',round(rand*100),round(rand*100));
         
      case(2)
          fprintf('%d-%d\n',round(rand*100),round(rand*100));
      case(3)
          fprintf('%d×%d\n',round(rand*100),round(rand*100));
      case(4)
         fprintf('%d÷%d\n',round(rand*100),round(rand*100));
   end
end

代码的截图:

 

 

运行的结果:

>> softwarehomework
请开始答题
98-44
11×26
41×59
26÷60
71÷22
12×30
32-42
51÷9
26×80
3-93
73÷49
58÷24
46×96
55×52
23×49
62+68
40-37
99-4
89+91
80÷10
26+34
68+14
72+11
65+49
78-72
90-89
33÷70
20-3
74+50
48÷90
>>

 

posted on 2018-10-07 10:00  刘浩20160729  阅读(104)  评论(0编辑  收藏  举报

导航