Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

High School Mathematics Extensions/Mathematical Programming/Output Routines

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Explanation Two new global variables were added: double x_val and double delta. Two new functions were added: void output() and double process(). One function was changed: void execute_command(char command). Global Variables double x_val: the value for x that is passed to f(x). double delta: the value by which x is changed when the + or - commands are executed. Function Additions void output() This function calls process to get the value of f(x) and then prints the message f(x)=value. double process() Executes the C implementation for f(x). Function Changes void execute_command(char command) Called the new function output to display f(x)=value. Implements the '-' and '+' commands for the variables x_val and delta. Code to change Add and replace the following code: //function prototypes //... float process(); void output(); //global variables //... float x_val; float delta; //function definitions //... void execute_command(char command) { switch (command) { case '=': output(); break; case '+': output(); break; case '-': output(); break; case 'd': case 'D': break; case 'x': case 'X': done++; break; } } float process() { return x_val * x_val; } void output() { float f_val; f_val=process(); cprintf("f(%f)=%6f.\n",x_val,f_val); } Next Step ../Input Revisited/ ../The Complete Program/