Question

In: Computer Science

MUST BE DONE IN C (NOT C++) Using an array and a function, print the values...

MUST BE DONE IN C (NOT C++)

Using an array and a function, print the values of an array backwards. Please follow these guidelines:

- Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer).

- Call your function. You should send two parameters to such function: the array’s length and the array.

- Inside the function, go ahead and print the array backwards.

- Your function shouldn’t return anything

Solutions

Expert Solution

Reversal of an array in C:

In the code below, I have sent 4 parameters to the function: the array, the position of the first element of the array, the position of the last element of the array, and the length of the array.

The main, driver function passed the above parameters to the revArray function. The revArray function, reverses the array and prints the output itself without returning anything.

The inputs are entered manually in the following code.

Code:

void rev(int arr[], int start, int end, int length)
{
int temp, i;
while (start < end)
{
temp = arr[start];   
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}   
printf("Reversed array is \n");
for (i=0; i < length; i++)
{
printf("%d ", arr[i]);
  
}
}   

int main()
{
int arr[] = {12, 23, 34, 45, 56, 67, 78, 89, 90};
int n = sizeof(arr) / sizeof(arr[0]);
rev(arr, 0, n-1, n);
}

Output:


Related Solutions

Using an array and a function, print the values of an array backwards. Please follow these...
Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything.
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add...
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add a range of values of an array. The range will be determined by the user. For example, if I have the following array … 1.5 -5.6 8.9 4.6 7.8 995.1 45.1 -5964.2 … and the user tells me to add from the 3rd element to the 6th element, my program would add the values 8.9, 4.6, 7.8 and 995.1. To do so, please follow...
Write a C++ function to print any given std::array of a given type to the standard...
Write a C++ function to print any given std::array of a given type to the standard output in the form of {element 0, element 1, element 2, ...}. For example given the double array, d_array = {2.1, 3.4, 5.6, 2.9}, you'd print {2.1, 3.4, 5.6, 2.9} to the output upon executing std::cout << d_array; line of code. Your function mus overload << operator.
In C++, write a function to fill an array of size 13 with values 13 11...
In C++, write a function to fill an array of size 13 with values 13 11 9 7 5 3 1 2 4 6 8 10 12 recursively, starting with the value 1 in the middle.
HOW TO PRINT THE CONTENTS OF A TWO-DIMENSIONAL ARRAY USING POINTER ARITHMETIC (USING FUNCTIONS) (C++) Fill...
HOW TO PRINT THE CONTENTS OF A TWO-DIMENSIONAL ARRAY USING POINTER ARITHMETIC (USING FUNCTIONS) (C++) Fill out the function definition for "void print_2darray_pointer(double *twoDD, int row, int col)". Should match the output from the function void print_2darray_subscript(double twoDD[][ARRAY_SIZE], int row, int col) # include using namespace std;    const int ARRAY_SIZE = 5;    const int DYNAMIC_SIZE = 15;    const int TIC_TAC_TOE_SIZE = 3;    // function definitions:    void print_2darray_subscript(double twoDD[][ARRAY_SIZE], int row, int col)        //...
MUST BE DONE IN C++ Use qsort( ) function in Visual Studio to sort the following...
MUST BE DONE IN C++ Use qsort( ) function in Visual Studio to sort the following three arrays: int array1 [] = { 3, 4, 2, 1, 7}; float array2 [] = {0.3, 0.1, 5.5, 4.3, 7.8}; char array3 [] = {‘c’, ‘d’, ‘a’, ‘b’, ‘f’};                                     Develop a driver function to print out the sorted results and put the screenshot into the word document. Note that you have to use qsort( ) provided by Visual Studio. What is the...
Get values for min and max using assignment statements and the input function. Print min and...
Get values for min and max using assignment statements and the input function. Print min and max. Run the script. fix any errors you find. Remove the print statements you wrote above. Print the labels "Kelvin" and "Fahrenheit". Print a line of dashes under the labels. Run the script. fix any errors you find. Write a for loop that will give the loop variable kelvin values between min and max. Inside the code block print the value of kelvin Run...
(MUST BE DONE IN C (NOT C++)) Instead of using two different variables, define a structure...
(MUST BE DONE IN C (NOT C++)) Instead of using two different variables, define a structure with two members; one representing the feet and the other one representing the inches. You will also use three functions; one to initialize a structure, another one to check the validity of its values and one last one to print them out. First, go ahead and define your structure. Next, declare a structure of this type inside main. Then, call your first function (this...
(C++ only please) Write a function called maximum that takes an array of double values as...
(C++ only please) Write a function called maximum that takes an array of double values as a parameter and returns the largest value in the array. The length of the array will also be passed as a parameter. (Note that the contents of the array should NOT be modified.) Write a function called printReverse that takes an array of characters and the length of the array as parameters. It should print the elements of the array in reverse order. The...
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT