Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A is a series of statements that are grouped together and given a name. The foll

ID: 3575627 • Letter: A

Question

A is a series of statements that are grouped together and given a name. The following code is for the function average, (which computes the average of two values, ) double average(int v1, int v1) {double temp; temp = (v1 + v2)/2.0; return temp;} The word specifies average's return type, the type of data returned to the calling function when the function is called. The identifiers v1 and v2 are the function's The statements between the curly braces are the of the function. The statement double average(int v1, int v1); would be known as the function or function The full six lines of code shown above are known as the function When a function's return type is the return statement must not have a value. If a function has no parameters, the key word should go between the parentheses (). Show (w rite) code to call the function average with two arguments, 3 & 7 and assign the return value to variable y. In C, all arguments in function calls are passed by or When a function parameter is a one-dimensional array, the length of the array should always be (specified or unspecified) in the square brackets. A function is recursive if it

Explanation / Answer

1) A function (function name: is average as given in the example) is a series of statements that are grouped together and given name.

2) The word double specifies average’s return type, the type of data returned to the calling function when the function is called.

3) The identifiers v1 and v2 are the function’s formal parameters or formal arguments

NOTE:

The parameters passed in function call is called actual argument

The parameters passed in function definition is called formal argument

4) The statements between the curly braces are the body of the function.

5) The statement double average(int v1, int v2); would be known as the function prototype or function declaration.

NOTE:

Parameters used in the function prototype are called formal parameters.

It is terminated by semicolon.

We can also write the function prototype without variable with only data types.

double average(int, int);

6) The full six lines of code shown above are known as the function definition.

NOTE: Function definition contains 2 parts:

a)Function header also called function signature

b)Function body enclosed within opening curly bracket ‘{’ and closing ‘}’

7) When a function’s return type is void, the return statement must not have value.

8) If a function has no parameters, the keyword void should go between the parenthesis().

9) Show (write) code to call the function average with two arguments, 3 and 7 assign the return value to variable y. y = average(3, 7);

NOTE: Assume variable y is declared as double

10) In C, all arguments in function call are passed by value or copy.

11) When a function parameter is one dimensional array, the length of the array should always be unspecified (specified / unspecified) in the square brackets.

NOTE: void show(int arr[])

12) A function is recursive if it calls itself.

NOTE:

a)If a function calls itself it is called recursive function.

b)If the function body contains call for itself it is called recursion.

Example:

#include<stdio.h>

//Returns the factorial of a number using recursion

long int Factorial(int n)

{

    //If entered number is greaterthan equal to 1 call Factorial function and pass parameter by deduction 1 from it

    if (n >= 1)

        return n * Factorial(n - 1);

    //Otherwise return 1

    else

        return 1;

}

int main()

{

    int n;

    printf("Enter a positive integer: ");

    scanf("%d", &n);

    printf("Factorial of %d = %ld", n, Factorial(n));

    return 0;

}

Output:

Enter a positive integer: 4

Factorial of 4 = 24

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote