Page 51 - Programming Microcontrollers in C
P. 51
36 Chapter 1 Introduction to C
4. Write a program that will examine a specified year and determine
if it is a leap year.
5. Write a program that will count the number of digits in an input
file. Record and print out the number of occurrences of each digit.
6. In C the term “white space” refers to the occurrence of a space, a
tab character, or a new line character. Write a program that will
evaluate the number of white space characters in an input file.
Program Flow and Control
Program flow and control comprise several different means to
control the execution of a program. Looping constructs, for example,
control the repeated execution of a program segment while adjusting
parameters used in the execution at either the beginning or the end of
the loop. Two way branches are created by if/else statements,
and the choice of one of many operations can be accomplished with
the else if or switch/case statements. The following para
graphs will provide a quick look at each of these program flow and
control methods.
The While Statement
There are three looping constructs available to the C programmer:
the while() statement, the for(;;) statement and the do/
while() statement. The following program demonstrates the use of
the while looping construct along with some other concepts. We have
seen the while statement earlier, but the following program will pro
vide a new look at its use.
#include <stdio.h>
int main(void)
{
int guess,i;
i=1;
guess = 5;
while(guess != i)
{