Programming in C
160 Chapter 8 Working with Functions unsigned long int factorial (unsigned int n) { unsigned long int result; if ( n == 0 ) resu ...
Recursive Functions 161 With the value of nequal to 2, the factorialfunction executes the statement result = n * factorial (n - ...
162 Chapter 8 Working with Functions Exercises Type in and run the 16 programs presented in this chapter. Compare the output pr ...
Exercises 163 represents a quadratic equation where a= 4,b= –17, and c= –15.The values of x that satisfy a particular quadratic ...
164 Chapter 8 Working with Functions Modify Program 8.14 so that the user is reasked to type in the value of the base if an inv ...
9Working with Structures 9 Working with Structures CHAPTER7, “WORKING WITHARRAYS,”INTRODUCEDthe array that permits you to group ...
166 Chapter 9 Working with Structures A Structure for Storing the Date You can define a structure called datein the C language t ...
A Structure for Storing the Date 167 Program 9.1 Illustrating a Structure // Program to illustrate a structure #include <stdi ...
168 Chapter 9 Working with Structures Figure 9.1. Assigning values to a structure variable. After the assignments have been made ...
A Structure for Storing the Date 169 defines an array called daysPerMonthcontaining 12 integer elements. For each month i, the v ...
170 Chapter 9 Working with Structures else if ( today.month == 12 ) { // end of year tomorrow.day = 1; tomorrow.month = 1; tomor ...
Functions and Structures 171 end of the month, tomorrow’s date is calculated by simply adding 1 to the day and set- ting tomorro ...
172 Chapter 9 Working with Structures struct date today, tomorrow; int numberOfDays (struct date d); printf ("Enter today's date ...
Functions and Structures 173 // Function to determine if it's a leap year bool isLeapYear (struct date d) { bool leapYearFlag; i ...
174 Chapter 9 Working with Structures is used. As you can see from the function call, you are specifying that the structure toda ...
Functions and Structures 175 int year; }; // Function to calculate tomorrow's date struct date dateUpdate (struct date today) { ...
176 Chapter 9 Working with Structures // Function to determine if it's a leap year bool isLeapYear (struct date d) { bool leapYe ...
Functions and Structures 177 illustrates the ability to pass a structure to a function and to return one as well.The dateUpdatef ...
178 Chapter 9 Working with Structures If the number of seconds reaches 60, the seconds must be reset to 0 and the min- utes inc ...
Functions and Structures 179 if ( now.seconds == 60 ) { // next minute now.seconds = 0; ++now.minutes; if ( now.minutes == 60 ) ...
«
5
6
7
8
9
10
11
12
13
14
»
Free download pdf