(Find the Error) Find the error in each of the following program segments and explain how to correct it:

a) ```
float cube( float ); // function prototype
cube( float number ) // function definition
{
return number * number * number;
}
```
b) ```
register auto int x = 7;
```
c) ```
int randomNumber = srand();
```
d) ```
float y = 123.45678;
int x;
```
e) ```
double square( double number )
{
double number;
return number * number;
}
```
f) ```
int sum( int n )
{
if ( n == 0 )
return 0;
else
return n + sum( n );
}
```

a) Error: The function definition defaults to a return type of int.
Correction: Specify a return type of float for the function definition.
b) Error: Only one storage class specifier can be used.
Correction: Remove either register or auto.
c) Error: Function srand takes an unsigned argument and does not return a value.
Correction: Use rand instead of srand.
d) Error: Variable number is declared twice.
Correction: Remove the declaration of variable number within the {}.
f) Error: Infinite recursion.
Correction: Change sum( n ) to sum( n - 1 ).

Computer Science & Information Technology

You might also like to view...

Match the following terms to their meanings: I. null II. AND logical operator III. OR logical operator IV. NOT logical operator V. wildcard A. special characters that represent one or more characters in a text value B. displays a data source C. query results will display only records that match all criteria D. a blank field E. query results will display records that match any of the specified

criteria What will be an ideal response?

Computer Science & Information Technology

_________________________ chart formatting is restricted greatly as compared to standard charts.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology