高中数学扩展/数学编程/练习 1:实现命令
外观
包括
类型定义
函数原型
全局变量
函数定义

//function definitions //... int get_integer() { int ret_val; char lastpress; cprintf("Enter integer: "); cscanf("%i",&ret_val); lastpress=getch(); cprintf("\n"); return ret_val; } //... void execute_command(char command) { switch (command) { case '/': output_divide(); break; case '%': output_modulus(); break; case '=': output_values(); break; case 'r': case 'R': r=get_integer(); output_values(); break; case 'l': case 'L': l=get_integer(); output_values(); break; case 'x': case 'X': done=TRUE; break; } } void output_divide() { if (r > 0) { cprintf("%d / %d = %d.\n",l,r,l/r); } else { cprintf("l = %d, r = %d. Please set r to a value other than 0.\n",r,l); } } void output_modulus() { if (r > 0) { cprintf("%d %% %d = %d.\n",l,r,l%r); } else { cprintf("l = %d, r = %d. Please set r to a value other than 0.\n",r,l); } } void output_values() { cprintf("l = %d, r = %d.\n",l,r); }