September 2001
Beginner
970 pages
23h 20m
English
Let's start with a simple example of an if statement shown in Listing 7.1. This program reads in a list of daily low temperatures (in Celsius) and reports the total number of entries and the percentage that were below freezing. It uses scanf() in a loop to read in the values. Once during each loop cycle, it increments a counter to keep track of the number of entries. An if statement detects temperatures below freezing and keeps track of the number of such days separately.
// colddays.c -- finds percentage of days below freezing #include <stdio.h> #define SCALE "Celsius" int main(void) { const int FREEZING = 0; float temperature; int cold_days = 0; int all_days = 0; printf("Enter the list of ... |
Read now
Unlock full access