1.3. Selection Example
p1.1.c (also see pythag.c) /* Program chapter1_1 modified to scale by largest side */ #include <stdio.h> #include <math.h> int main(void) { double x1=1e200, y1=5e200, x2=4e200, y2=7e200, side_1, side_2, distance, scale; side_1 = fabs(x2 - x1); side_2 = fabs(y2 - y1); if( side_1 > side_2) scale = side_1; else scale = side_2; side_1 /= scale; side_2 /= scale; distance = sqrt( side_1*side_1 + side_2*side_2); distance *= scale; printf("distance = %g\n", distance); return 0; } /* output: distance = 3.60555e+200 */ |
Flowchart of selection statement (if/else) |