高中數學擴充套件/數學程式設計/練習 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);
}