问题 单项选择题

设a、b都是自然数,为求a除以b的余数,某人编写了以下函数:
Function fun(a As Integer,b As Integer)
While a>b
a=a-b
Wend
fun=a
End Function
在调试时发现函数是错误的。为使函数能产生正确的返回值,应做的修改是______。

A) 把a=a-b改为a=b-a
B) 把a=a-b改为a=a\b
C) 把While a>b改为While a<b
D) 把While a>b改为While a>=b

答案

参考答案:D

解析: 当a=b时,余数应该为O,而不是a,程序执行结果会跳出循环使fun=a,应该继续循环,正确答案为D) 。

多项选择题
填空题