CMSC201 Midterm Exam Review
Fall 2008


Picture ID required for the MidTerm

These questions are sample questions.

The questions below may be modified by being reworded (i.e. true statements may be made false), by changing variable names, constants, etc. if included on the midterm. Functions you are asked to write or analyze may not be exactly the same as those listed here. 


True/False Questions

Circle TRUE or FALSE for each of the following questions.
  1. TRUE/FALSE
    In Unix, the command rm can be used to delete files.
  2. TRUE/FALSE
    In Unix, the mv command is used to move to a different directory.
  3. TRUE/FALSE
    In Unix, the command to make a copy of a file is cp.
  4. TRUE/FALSE
    The following command given at the Unix prompt a.out < input.dat is called redirection and causes the contents of the input.dat file to be used as input to the program.
  5. TRUE/FALSE
    Once a text file has been created with emacs or xemacs, it may only be editted with emacs or xemacs.
  6. TRUE/FALSE
    When statements (e.g., while statements) are nested inside other statements, the compiler uses the indentation to determine the scope of each statement.
  7. TRUE/FALSE
    A function that returns no result and is executed only for its effect is called a procedure.
  8. TRUE/FALSE
    A function that returns no result and is executed only for its effect is called a predicate function.
  9. TRUE/FALSE
    If n is an integer variable, the value of the expression n % y is 0 whenever n is a not a multiple of y.
  10. TRUE/FALSE
    If n is an integer variable, the value of the expression n % 10 is always less than 10.
  11. TRUE/FALSE
    The prototype of a function is used mainly as a comment to the reader, but is not useful to the compiler.
  12. TRUE/FALSE
    A function prototype gives the compiler the value returned by the function.
  13. TRUE/FALSE
    A function prototype tells the compiler the type of the value that is returned by the function.
  14. TRUE/FALSE
    All functions must return a value.
  15. TRUE/FALSE
    When a function is called its local variables initially contain the value 0.
  16. TRUE/FALSE
    A function with return type void always returns the value 0.
  17. TRUE/FALSE
    When a function is called the number of arguments passed should match the number of formal parameters given in the function's prototype.
  18. TRUE/FALSE
    After a function has returned, the values stored in its local variables are copied into variables in the main function with the same name.
  19. TRUE/FALSE
    The values stored in the local variables of a function are not saved when the function exits.
  20. TRUE/FALSE
    The preprocessor directive #include "foo.h" instructs the preprocessor to place the contents of the file foo.h into the code at that point.
  21. TRUE/FALSE
    A header file typically contains constant definitions, function prototypes and function definitions.
  22. TRUE/FALSE
    In UNIX, the file foo.o usually contains the the machine language translation of the source code file foo.c.
  23. TRUE/FALSE
    In order to compile a program, the source code for every function used by the program must be placed in a single file.
  24. TRUE/FALSE
    The #include preprocessor directive is used to insert one file into another.
  25. TRUE/FALSE
    What is the value of the C expression 2 * 6 - 5 + 8 % 5
  26. TRUE/FALSE
    If the integer variables a and b are holding the values 0 and 1, respectively, what is the value of the following expression : (a || b ) ?
  27. TRUE/FALSE
    If the integer variables a and b are holding the values 0 and 1, respectively, what is the value of the following expression : (a && b ) ?
  28. TRUE/FALSE
    What is the value of the C expression 3 * 5 - 12 ?
  29. TRUE/FALSE
    According to DeMorgan's law, !(x && y) is equivalent to (!x) && (!y)
  30. TRUE/FALSE
    According to DeMorgan's law, (!x) || (!y) is equivalent to !(!x && !y)
  31. TRUE/FALSE
    If the integer variables a and b are holding the values 0 and 6, respectively,
    after the statement a += b++ the new values of a and b are both 7.
  32. TRUE/FALSE
    If the integer variables a and b are holding the values 5 and 2, respectively, the expression
    a / b produces the result 2.5
  33. TRUE/FALSE
    If the integer variables a and b are holding the values 5 and 2, respectively, and c is a double, after executing the statement c = a / b ;, the value of c is 2.5
  34. TRUE/FALSE
    A procedure returns a 0 or a 1.
  35. TRUE/FALSE
    A procedure has no return value.
  36. TRUE/FALSE
    A predicate function returns a 0 or a 1.
  37. TRUE/FALSE
    In C, "false" is always equivalent to 0.
  38. TRUE/FALSE
    In C, "true" is always equivalent to 1.
  39. TRUE/FALSE
    A call to the srand() function returns a pseudo-random integer.
  40. TRUE/FALSE
    A call to the rand() function returns a pseudo-random integer.
  41. TRUE/FALSE
    A call to the srand() function initializes the pseudo-random number generator.
  42. TRUE/FALSE
    The value of the expression rand() % 5 is an integer between 1 and 5 inclusive.
  43. TRUE/FALSE
    The value of the expression rand() % 7 + 1 is an integer between 1 and 7 inclusive.
  44. TRUE/FALSE
    In C, all arrays passed to functions are passed by reference.
  45. TRUE/FALSE
    When an array is passed to a function, only the address of the array is passed to the function.
  46. TRUE/FALSE
    When an array is passed to a function, a copy of the elements is made and passed to the function to manipulate.
  47. TRUE/FALSE
    The preprocessor directive #define RING 1 tells the C preprocessor to replace each occurrence of the constant RING with 1.
  48. TRUE/FALSE
    Some compilers assume that any function without a prototype returns an int.
  49. TRUE/FALSE
    You must use the newline ('\n') character to start printing at the beginning of the next line.
  50. TRUE/FALSE
    A C program that prints three lines of output must contain three printf statements.
  51. TRUE/FALSE
    The default case is required in the switch selection structure.
  52. TRUE/FALSE
    The cases in a switch statement must be listed in ascending order.
  53. TRUE/FALSE
    The default case must be the last case in the switch selection structure.
  54. TRUE/ FALSE
    An array can store many types of values simultaneously.
  55. TRUE/ FALSE
    Array subscripts must always start at 0.
  56. TRUE/ FALSE
    The fourth element of an array named foo is foo[4]
  57. TRUE/FALSE
    All arrays with 10 elements require the same amount of memory.
  58. TRUE/FALSE
    typedef is used to give a new name to a known data type.
  59. TRUE/FALSE
    In C, a parameter is passed by VALUE when a copy of the value of a variable is passed to the function.
  60. TRUE/FALSE
    Structures in C must have members which are of the same type.
  61. TRUE/FALSE
    Structures in C may have members which are of different types.
  62. TRUE/FALSE
    The members of different structures used within the same program must have unique names.
  63. TRUE/FALSE
    Local variables within main() may not have the same name as the member of any structure used within main().
  64. TRUE/FALSE
    A structure cannot have two members of the same type.
  65. TRUE/FALSE
    A member in a structure can itself be a structure.
  66. TRUE/FALSE
    A structure cannot have two members with the same name.
  67. TRUE/FALSE
    If rec is a structure variable and number is a member of the structure, then to access the number member of rec use the syntax rec.number
  68. TRUE/FALSE
    The string "Bilbo Baggins", may be stored in an array of 13 characters.

Multiple Choice Questions

  1. Which of the following items belong in a header file?
  2. A C library contains
  3. The on-line manual on the UNIX system provides the following information about a function you may want to use, except
  4. Suppose that the header file foo.h contains the function prototype of the function UseMe. You should include foo.h in the file mine.c
  5. What is the value of the expression 12 - 10 - 8 * 6 % 4 + 2 % 1
  6. What is the output of the following code fragment? int a = 3, b = 17 ; a = b % a ; b = ++a + 5 ; printf("a = %d, b = %d\n", a, b) ;
  7. Execution of a break statement in the body of a while loop
  8. Execution of a continue statement in the body of a for loop
  9. Determine the output of the code fragment. int a = 4, b = 3, c = 1 ; if ( a < b + 1 ) { printf("Stop and smell the roses.\n") ; } else if ( a > b + c ) { printf("Type A personality.\n") ; } else if ( a % b >= c ) { printf("What doesn't kill me, makes me stronger.\n") ; } else { printf("I sense a lot of anxiety in this room.\n") ; }
  10. What is the effect of the following code? int i, total ; for (i = 1 ; i <= 15 ; i++) { if ( i % 3 == 0) { printf("%d ", i) ; } } printf("\n\n");
  11. The following Boolean expression is equivalent to which of the given expressions? !( a == 12 || n > 15 )
  12. Which of the following is the function prototype for a function AlphaBeta that takes two double parameters and does not return any values.
  13. Which of the following is the function prototype for a function Foo that takes one double parameter and returns an integer value.
  14. Which of the following is the function prototype for a function Bar that takes two integer parameters and returns a double value
  15. In order to include a header file which is in your current working directory, which of the following would be used ?
  16. When an array parameter is passed to a function
  17. Let arr be an array of integers, then in the expression arr[i++]
  18. A single C statement that assigns the sum of x and y to z and then increments the value of x by 1 after the calculation.
  19. A single C statement that decrements the variable x by one then subtracts it from the variable total is
  20. A single C statement that adds the variable x to the variable total and then decrements x by one is
  21. Assuming that the variables x and product each have the value 5, then the new values of x and product after the statement product *= x++; are
  22. Assuming that the variables high and low contain the values 3 and 5, respectively, then the new values of high and low after the statement high *= --low + 4 are
  23. The main difference between a struct and an array is:
  24. Which of the following can NOT be done with a structure variable ?
  25. The expression sizeof(int) refers to
  26. The expression sizeof(struct foo) refers to
  27. A segmentation fault occurs when
  28. The typedef facility is used to
  29. The third element in the 2nd row of a 7 - by - 5 integer array named maze is
  30. The statement printf ("%-30s", "Dan");

Short Answers

In the following questions, no syntax errors have put in deliberately. (So, "there is a syntax error" is NOT the right answer and will receive no credit.) Please mark your final answer clearly. In order to receive partial credit, you must show your work.
  1. What is the Unix command to list all the files in the current directory?
  2. What is the Unix command to change the current working directory?
  3. What is the Unix command to display the name of the current working directory?
  4. Assuming a file named foo.c exists in the current directory, what is the Unix command to rename foo.c to bar.c?
  5. What is the Unix command to create a new directory named cmsc201?
  6. What is the Unix command to delete the file named circle.c?
  7. What is the Unix redirection command that will place the output from an executable, a.out, into a file called output.txt ?
  8. Write a function called ArrayMin that returns the minimum value in an array of n integers, where array and n are parameters passed to the function.
  9. Give an example of how ArrayMin would be called from main.
  10. Write a function called SumArray that returns the sum of the first n elements of an array of floats, where array and n are parameters which are passed to it.
  11. Write a C code fragment using a for loop that prints the numbers 1 to 5 side-by-side on the same line with 4 spaces between each number
  12. Write a C code fragment using a while loop that prints the even numbers between 1 and 9 (inclusive)side-by-side on the same line with 5 spaces between each number
  13. Write a C code fragment using a for loop that calculates and and prints the sum of the even integers from 2 to 30, inclusive.
  14. When passing arguments to a function, what's the difference between "passing by value" and "passing by reference" ?
  15. Given the structure definition/declaration below, write a printf() statement which prints today in the form month/day/year. struct date { int year; int month; int day; } today ;
  16. Give a function prototype for a function called Hypotenuse that takes two double precision floating point arguments, side1 and side2 and returns a double precision floating point result. DO NOT write the code.
  17. Give a function prototype for a function called Smallest that takes three integer arguments, x, y and z and returns an integer. DO NOT write the code.
  18. Write a single C statement that will print a random number from the set 2, 4, 6, 8, 10
  19. How are the elements of an array stored in memory ?
  20. All programs can be written in terms of three control structures: _____________________, ______________________ and ___________________.
  21. Rewrite the following code segment that uses a for loop as an equivalent code segment that uses a while loop. for (i = LOWER; i <= UPPER; i++) { if (i % 5 == 0) { printf("%d is a multiple of 5\n", i); } else { printf("%d is not\n", i); } }
  22. What is the output of the following program? Don't wory about the exact number of spaces to appear before or after any numeric output. If the program goes into an infinite loop, you need show only the first five lines of output. Assume that the program as shown compiles correctly. #include <stdio.h> int Mickey(int, int) ; int Mouse(int) ; int main() { int a = 2, b = 3, c = 3 ; a = Mickey (b + 5, c) ; b = Mouse (c) ; printf ("main: a = %d, b = %d, c= %d\n", a, b, c) ; return 0 ; } int Mickey (int x, int y) { int z ; z = x - y ; printf ("Mickey: x = %d, y = %d, z = %d\n", x, y, z) ; return (z) ; } int Mouse (int c) { int a, b ; a = 1 ; b = c * 2 + a ; a = b + 5 ; c = Mickey (a, b) ; printf ("Mouse: a = %d, b = %d, c = %d\n", a, b, c) ; return (b) ; }
  23. This question tests your knowledge of nested for loops. Please put carriage returns in the proper places. What is the output of the following code ? int i, j; for (i = 0; i <= 3; i++) { for (j = 0; j <= 4; j++) { if ( (i + 1 == j) || (j + i == 4) ) { printf ("+"); } else { printf ("o"); } } printf ("\n"); }
  24. In the nested for loop code above, how many times is the condition of the if clause evaluated ?
  25. Write a simple loop which prints out the following sequence of numbers: 18 23 28 33 38 43 48
  26. What's the difference between a function's prototype and its header ?
  27. Write a program that inputs 2 floating point values from the keyboard and displays their product.
  28. Write a program that gets 10 integer values that are input from the keyboard, then displays their sum.
  29. Which of C's data types can be used in an array ?
  30. In a one-dimensional array with n elements, what is the index of the last element ?
  31. Write the statement(s) that would declare a 10-element integer array and initialize all of its elements to 1.
  32. Write a declaration for a 3 - by - 6 integer array named array.
  33. Write a function called Average that takes three integer parameters n1, n2, and n3 and returns the value of the average of the three as a double.
  34. Write a function called Harmonic that takes an integer parameter n, and returns the following sum: 1/1 + 1/2 + 1/3 + . . . + 1/n This is called a partial Harmonic series. The various fractions, and the returned value should be of type double.
  35. Given the structure definitions below typedef struct { int x; int y; } POINT; typedef struct { POINT start; POINT end; } LINE; Write a function called MakeLine() that takes two parameters of type POINT and returns a structure of type LINE representing the line segment that connects the two points.
  36. Given the definitions of POINT and LINE above, write a function called LineType() that takes a structure of type LINE and returns a character (v, h or o) where v means vertical, h means horizontal and o means oblique. A vertical line is a line whose x-coordinates are the same. A horizontal line in a line whose y-coordinates are the same. Any other line is oblique.
  37. Given the structure definition below, write a scanf() statement which reads in the quantity member of p. struct part { int partNum; char description[30]; int quantity; char type; }; struct part p;
  38. Write a function called NumDigits that has a single formal parameter of type int and returns the number of digits in that integer.
  39. Write a predicate function called IsEven that takes an integer, n, as its single argument and returns "true" if n is even and "false" if n is not even.
  40. Fill in the blanks below. The function FindNet computes a worker's weekly net pay given hours (an integer), rate (a double), and exempt (an int used as a boolean) as input parameters. The net pay for the worker should be returned as a double. If the worker turns in more than forty hours and the value of exempt is FALSE, then pay 1 1/2 times the normal rate ("time and a half") for any hours worked over forty. If gross pay exceeds $800, subtract 33% for taxes. Otherwise, subtract 25% for taxes. Include a statement to print the worker's hours and net pay for the week. (The net pay will be in dollars and cents, so choose the output format accordingly. The number of underscore characters shown is not necessarily an indication of the length of the correct response.) ________ FindNet ( int hours, ________ ______ , int _______ ) { double ________ , __________ ; int ___________ ; if ( _______ > 40 _____ (!exempt ) ) { extraHours = hours - 40; grossPay = (40 * _______ ) + extraHours * (rate * _____); } else { grossPay = hours * _______ ; } if (grossPay > ________ ) { netPay = grossPay - grossPay * _______ ; } _________ { netPay = grossPay - grossPay * _______ ; } ________ ("Hours = %d and Net Pay = _______ \n", hours, netPay); ________ ( __________ ); }
  41. Fill in the blanks below. The function CalculateLabScore calculates the total lab score by dropping the two lowest lab scores and summing the remaining scores. The number of underscore characters shown is not necessarily an indication of the length of the correct response. /******************************************************* * CalculateLabScore() * calculates the total lab score by dropping the two lowest * lab scores and summing the remaining scores. * * Input: the array of scores and its size * Output: the total of the scores after the two lowest * scores are dropped. *******************************************************/ _________ CalculateLabScore(int scores________, int ____________) { int i, temp, totalScore = _________; int lowest, nextLowest, lowestIndex, nextLowestIndex; /* find lowest value */ lowest = scores[_____]; lowestIndex = _____; for(i = 1; i < size; i++) { if(scores[i] < _____________) { lowest = scores[i]; __________________ = i; } } /* move the lowest value to the end of the */ /* array by swapping it with the last element */ ______________ = scores[lowestIndex]; scores[lowestIndex] = scores[size-1]; scores[size-1] = ______________; /* find the next to the lowest value */ /* don't examine last element since */ /* it is holding the lowest score */ _________________ = scores[0]; nextLowestIndex = 0; _______(i = 1; i < __________________; i++) { if(scores[i] < __________________) { nextLowest = scores[i]; nextLowestIndex = i; } } /* move the next to the lowest value to the */ /* next to the last position in the array by */ /* by swapping it with the next to last element */ temp = scores[nextLowestIndex]; scores[nextLowestIndex] = scores[________________]; scores[________________] = temp; /* sum all but the 2 lowest scores */ for(i = 0; i < _____________; _______) { totalScore ________ scores[i]; } return _____________; }
  42. Fill in the blanks in the function below. This function calculates a gymnast's score by removing the highest and lowest score from an array of 10 floating point values, (ranging from 0.0 to 10.0) then averaging the other 8. #define NR_SCORES __________ ______ Gymnastics (____________ scores[NR_SCORES]) { int i; float sum = _______; float lowest = 11.0; float __________ = -1.0; for (i = 0; i < ________; i++) { sum += _______________; if (_________________________) { lowest = scores[i]; } if (_________________________) { highest = scores[i]; } } sum -= highest; sum -= ______________; return ( _______________ ); }
  43. Fill in the blanks below. The function PrintRandomPhoneNumber generates and prints a random seven-digit phone number that adheres to the rules for phone numbers in the United States. Those rules are: The function takes the seed for the pseudo-random number generator as its single parameter of type int. Choose the output format to guarantee proper printing of the phone number. (The number of underscore characters shown is not necessarily an indication of the length of the correct response.) ________ PrintRandomPhoneNumber ( ________ seed ) { int digit1 , ________, digit3, firstThree, lastFour; /* Seed the random number generator */ _____________(seed); /* Generate the first two digits individually */ digit1 = rand( ) ______ 8 + 2; ________ = rand ( ) % ________ + ________ ; /* Generate the third digit */ ________ = rand ( ) % ________ ; /* Calculate the 3-digit integer called firstThree */ firstThree = digit1 * ________ + ________ * _______ + digit3; /* Generate a four-digit integer */ lastFour = ________ ( ) % ________ ; /* Print the random phone number */ ___________ ("_______-_______\n", ____________, ______________ ); }
  44. Write a function called RollDice( ) that takes no arguments and returns the result of rolling two six-sided dice. You may assume that the pseudo-random number generator has already been seeded in main() or some other function before RollDice( ) is called.
  45. Write the function CountVowels( ) that examines an array of n characters and returns the total number of vowels (a, e, i , o , u).
  46. Write the function Stars() whose inputs are an array of characters (a), the size of the array (n), and a character (c). This function should replace all occurrences of 'c' in the array, a, with a star (*) and return the number of times the replacement was made.
  47. Write the function VowelStars() whose inputs are an array of characters (a), and the size of the array (n). This function should replace all vowels ('a', 'e', 'i', 'o', 'u') with a star (*) and return the number of times the replacement was made.
  48. Describe what the function below does. The parameter a is 2-dimensional array of positive floating point numbers. float Bob (float a[10][5]) { float x = 0.0; int i, j; for (i = 0; i < 10; i++) { for (j = 0; j < 5; j++) { if (a[i][j] > x) { x = a[i][j]; } } } return x; }
  49. Under what conditions will this code fragment print "water" ? if(temp < 32) { printf("ice\n"); }else if (temp < 212) { printf("water\n"); }else { printf("steam\n"); }
  50. What's wrong with this code fragment ? int a[5]; for(i = 1; i <= 5; i++) { a[i] = 0; }
  51. Describe top-down design.
  52. A "test harness", also known as a "driver" - What is it and when is it used ?
  53. Draw a "design diagram" for the following project: Project description: This project allows the user to compute the volume and surface area of boxes, when s/he inputs the length, width and height of a box. The user can continue to enter the dimensions of new boxes until s/he is done.
  54. Give the prototypes for at least two of the functions you would use in the project described in the previous question (other than PrintGreeting()) and describe their purpose.
  55. Write a function called Add3Even() that examines an array of n integers and returns the sum of the first 3 even values it finds. You may assume that there will be at least 3 even integers in the array.
  56. Write the function LargestOdd that examines the contents of an integer array with n elements and returns the largest odd integer in the array. If there are no odd integers in the array, return 0.
  57. Write a function called Doubler that takes a single integer parameter, n, and returns (as an integer) the number of times n must be doubled to get to or exceed 1,000,000.
  58. Write a function called Scan(), which takes a string and a character as its two parameters and returns an integer which is the number of times the given character appears in the string.
  59. Write a function CountVowels() that examines a string and returns the total number of vowels in that string (a, e, i, o, u).
  60. Write a function Stars() whose inputs are an array of characters (a), the size of the array (n), and a character (ch). This function should replace all occurrences of ch in the array, a, with a star (*) and return the number of times the replacement was made.
  61. Write a function VowelStars() whose inputs are an array of characters (a), and the size of the array (n). This function should replace all vowels ('a', 'e', 'i', 'o', 'u') with a star (*) and return the number of times the replacement was made.
  62. Write a definition for a struct named book which contains three members:
    1. a string title of at most 50 characters
    2. a string author of at most 50 characters
    3. an integer variable checkedOut.
  63. What is the empty string ? How big should the array be that stores the empty string ? What would the function strlen() return when it is passed the empty string ?
  64. Print 1.234 in a 9-digit field with leading zeros.
  65. What happens if your program tries to access an array element with an out-of-range subscript ?
  66. Write a set of one or more if statements that will print out one of the brief messages given in the table below, depending on a person's grade point average. Assume that the grade point average has already been read into a variable called gpa. Include code to print a warning message if the value of gpa is not in the range 0.0 to 4.0.

    gpa range student rating
    3.50 - 4.0  Dean's list 
    2.0 - 3.49  Satisfactory 
    1.0 - 1.99  Probation 
    0.0 - 0.99  Suspended 

  67. Determine the output of the following program segment: int a = 17, b; b = a; printf ("b = %d\n", b); b = b + 1; printf ("b = %d\n", b); b = a / b; printf ("b = %d\n\n\n", b);
  68. Given: int a = 5, b = 7, c = 15; Evaluate each expression below as TRUE or FALSE. _______ (1) c / b == 2 _______ (2) c % b <= a % b _______ (3) b + c / a != c - a _______ (4) (b < c) && (c == 7) _______ (5) (c + 1 - b == 0) || (a = 5)

    Determine the output generated by the following code segments, assuming the surrounding program code (whatever it is) compiles correctly.

  69. int a = 2, b = 3; b *= a; a += b++; printf ("%d %d\n", a, b);
  70. int m = 5, n = 8; printf ("%d %d\n", m % n, n % m);
  71. int x = 12, y = 28; printf ("%d %d\n", x / y, y / x);
  72. #include <stdio.h> #define SIZE 10 int Mystery (int a[], int n); int main ( ) { int foo[SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; printf ("Mystery returns %d\n", Mystery (foo, SIZE)); return 0 ; } int Mystery (int a[], int n) { int x = 0; int i; for (i = 0; i < n; i++) { if (i % 2 == 0) { x += a[i]; } } return x; }
  73. Briefly describe in English what the function "Mystery" used above does. Describe the large task it accomplishes, not the individual steps.



  74. void F (int x); void G (int x); int main () { G (4); F (5); G (6); return 0; } void F (int x) { printf ("%d ", x); } void G (int x) { F (x + 1); printf ("%d ", x); }
  75. #include <stdio.h> int X (int m); int Y (int n); int main () { int r, s; r = X (12); s = Y (7); printf ("main: %d %d\n", r, s); return 0; } int X (int m) { printf ("X: %d\n", m); return (m + 2); } int Y (int n) { printf ("Y: %d %d\n", n, X (n)); return (n * 3); }
  76. int F (int x); int main() { printf ("%d %d", F (5), F (F (7)) ); return 0; } int F (int x) { return 2 * x + 1; }
  77. int a = 2, b = 11; b += a; a -= ++b; printf ("%d %d\n", a, b); a = 13; b = 5; printf ("%d %d\n", a / b, b / a); printf ("%d %d\n", a % b, b % a);
  78. int x = 1; if (x > 3) { if (x > 4) { printf ("A"); } else { printf ("B"); } } else if (x < 2) { if (x != 0) { printf ("C"); } } printf ("D");
  79. int n = 1234; while (n > 0) { n /= 10; printf ("%d\n", n); }
  80. int j, k; for (j = 1; j <= 4; j++) { for (k = 1; k <= j; k++) { printf ("*"); } printf ("\n"); }
  81. int g, h; for (g = 1; g <= 3; g++) { for (h = 0; h < 3; h++) { if (g == h) { printf ("O"); } else { printf ("X"); } } printf ("\n"); }
  82. int m; for (m = 1; m <= 5; m++) { switch (m) { case 1: printf ("one"); break; case 2: printf ("two"); break; case 3: printf ("three"); break; default: printf ("Default case"); } printf ("\n"); }
  83. int F1 (int a, int b); int F2 (int b, int c); int main() { int a = 2, b = 5, c = 7; c = F1 (a, b); printf ("main: %d %d %d\n", a, b, c); b = F2 (a, c); printf ("main: %d %d %d\n", a, b, c); return 0; } int F1 (int a, int b) { printf ("F1: %d %d\n", a, b); return a; } int F2 (int b, int c) { printf ("F2: %d %d\n", b, c); return c; }
  84. int F1 (int a, int b); int F2 (int a, int b); int main() { int a = 2, b = 4, c = 6; c = F1 (a, b); printf ("%d %d %d\n", a, b, c); b = F2 (a, c); printf ("%d %d %d\n", a, b, c); a = F2 ( F1 (a, c), b); printf ("%d %d %d\n", a, b, c); b = F2 (a, c) / F1 (b, c); printf ("%d %d %d\n", a, b, F1 (a, b) ); return 0; } int F1 (int a, int b) { return (a + b + 3); } int F2 (int a, int b) { return ( (a + b) % 3 ); }