File tree Expand file tree Collapse file tree 1 file changed +27
-15
lines changed
Expand file tree Collapse file tree 1 file changed +27
-15
lines changed Original file line number Diff line number Diff line change 33
44int32_t f (int32_t x );
55int scan_x (int32_t * x );
6+ void execute_print (int32_t x );
67void print_fx (int32_t x , int32_t y );
78
89int main ()
910{
10- // (I)
11- int32_t x = 0 ;
11+ int32_t x ;
1212 int result = scan_x (& x );
13- printf ("Read %i parameters from user input. " , result );
14-
15- // (P)
16- int32_t y1 = f (1 * x );
17- int32_t y2 = f (2 * x );
18- int32_t y3 = f (3 * x );
19- int32_t y4 = f (4 * x );
20-
21- // (O)
22- print_fx (1 * x , y1 );
23- print_fx (2 * x , y2 );
24- print_fx (3 * x , y3 );
25- print_fx (4 * x , y4 );
13+ if (result == 1 )
14+ {
15+ execute_print (x );
16+ }
17+ else if (result == EOF )
18+ {
19+ printf ("IO Error!" );
20+ }
21+ else
22+ {
23+ printf ("The input must be a number!" );
24+ }
2625}
2726
2827int32_t f (int32_t x )
@@ -36,6 +35,19 @@ int scan_x(int32_t* x)
3635 return scanf_s ("%i" , x );
3736}
3837
38+ void execute_print (int32_t x )
39+ {
40+ int32_t y1 = f (1 * x );
41+ int32_t y2 = f (2 * x );
42+ int32_t y3 = f (3 * x );
43+ int32_t y4 = f (4 * x );
44+
45+ print_fx (1 * x , y1 );
46+ print_fx (2 * x , y2 );
47+ print_fx (3 * x , y3 );
48+ print_fx (4 * x , y4 );
49+ }
50+
3951void print_fx (int32_t x , int32_t y )
4052{
4153 printf ("f(%i) = %i, " , x , y );
You can’t perform that action at this time.
0 commit comments