Monday, April 1, 2013

A simple if statement



/* A simple if statement */
#include <stdio.h> int main (void) { int temp; printf ("What is the current temperature? "); scanf ("%d", &temp); printf ("------------------------------------\n"); /* this if statement contains a true and a false branch */ /* with a compound statement in each branch*/ if (temp >= 20) { printf ("The temperature is %d degrees. \n", temp); printf ("It is quite warm. \n"); } else { printf ("The temperature is %d degrees. \n", temp); printf ("It is quite cool. \n"); } return (0); }
Legend: preprocessor directives | variable declarations | main program | helper functions | user-defined structures | comments
What is the current temperature? 13
------------------------------------
The temperature is 13 degrees.
It is quite cool.

2 comments: