![]() ![]() | control/bool-assignment.c - To assignments til boolske konstanter i en if - unødvendig omstændeligt. | Lektion 3 - slide 16 : 25 Program 1 |
#include <stdio.h> int main(void) { double x, y; int is_x_smaller_than_y; printf("Enter two real numbers: "); scanf("%lf %lf", &x, &y); /* Find out if x is less than y - in a primitive way ... */ if (x < y) is_x_smaller_than_y = 1; else is_x_smaller_than_y = 0; /* Print result */ if (is_x_smaller_than_y) printf("%f is smaller than %f\n", x, y); else printf("%f is greater than or equal to %f\n", x, y); return 0; }