Functions & rand() problems

 

1.)

Write C Statements that assign random integers to the variable n in the following ranges:

  1. 1< n < 2
  2. 1< n < 100
  3. 0< n < 9
  4. 1000 < n < 1112
  5. -1 < n < 1
  6. -3 < n < 11

 

 

2.)

Write a function called multiple that determines for a pair of integers whether the second integer is a multiple of the first. The function should take two integer arguments and return 1 (true) if the second is a multiple of the first, and 0 (false) otherwise.

 

 

3.)

Find the errors in each of the following program segments and explain how to correct them:




a.)

float cube(float);   /* function prototype */
........
........
cube (float number)     /* function definition */
{
     return number  *  number   *  number;
}


b.)

int  randomNumber = srand();



c.)

float  y = 123.45677;
int x;

x=y;
printf("%f\n", (float) x);



d.)

double square(double number)
{
   double number;

   return     number  *  number;

}



e.)

The following code should print whether a given integer
is odd or even:

switch ( value % 2 ) {
     case 0:
        printf ( " Even integer \n " );
     case 1:
        printf ( " Odd integer \n " );
}

 

 

4.)

Write a function integerPower ( base, exponent) that returns the value of

(base)exponent

For example, integerPower( 3, 4) = 3 * 3 * 3 * 3 . Assume the exponent is a positive, nonzero integer, and base is an integer. The function integerPower should use a for loop to control the calculation. Do not use any math library functions.

 

 

5.)

What does the following code print?

int  x ,  y ;
x = 0;
y = 1;

if  ( x  <  y    | |     y  <  5    & &     x  = =  3 )
{
    printf ( " True  \ n " );
{
else
{
    printf ( " Flase \ n " );
}