Starting from:
$23

$17

Programming Exercise Solution

1. Explain the output of the following program. Does interchanging the arguments in the last printf () statement make any difference?

#include<stdio.h

int main (void)

{

char a=127, b=128;

printf ("%5d %5d %5d\n", a, a+1, b);

printf (%5d %5d %5d %5d\n", a, a += 1, b, a);

return 0;

}

output:

127 128   -128

127 -128    -128   -128

 

2. Write a function, timeUpdate ( ), which is passed three int parameters, hour, min, sec, representing the current time and returns the time updated by one second. The function should work with a 24-hour clock where 4:30 a.m. is represented by 4:30 and 4:30 p.m. is represented by 16:30.

 

 

3. Answer the following questions regarding an array called num.

a) Name the fourth element from the beginning of the array.

b) Display the value of the fith element of the array.

c) Input a value into second element of array num.

d) Initialize each of the 10 elements of the array to 8

e) Total elements of array num into summation variable sum.

f) Copy the contents of array num into array f, also of size SIZE.

 

 

4. As a practical joke, a friend gives you an int array for your birthday. As if that were not bad enough, your friend tell you that the array contains almost all 0's except for a small string of consecutive 1's contained somewhere in the middle. Overwhelmed by the novelty of this you decide to write a function that will print out the location of the first 1 in the array, the location of the last one in the array, and the total number of 1's in the list of consecutive 1 values. Given below is the function prototype:

void joke (int num [ ], int max);

where num is the array of int values and max contains the number of elements in the array.

 

 

5. Write a preprocessor directive to accomplish each of the following:

a) Define macro SUM that will sum two numbers.

b) Define macro MIN2 that will determine the smallest of two numeric values.

More products