Question

In: Computer Science

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.

Solutions

Expert Solution

Solution:

Since no programmming language is specified I have provided the algorithm,pseudocode and a program in C++ language.

Algorithm for function:

START
   Step 1 → Loop for each value of A in reverse order 
   Step 2 → Display A[n] where n is the value of current iteration
STOP

Pseudocode of function:

procedure print_reverse(len,Array)

   FOR i from len-1 to 0
      DISPLAY A[i]
   END FOR
   
end procedure

C++ code of function:

void print_reverse(int len,int array[])
{
        int i=0;
        for(i = len-1; i >= 0; i--)
      cout<<array[i]<<" ";  
}

Complete implementation of code with main function:

#include <iostream>

using namespace std;

void print_reverse(int len,int array[])
{
        int i=0;
        for(i = len-1; i >= 0; i--)
      cout<<array[i]<<" ";  
}

int main() {
   int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
   int n=10;
   print_reverse(n,array);
   return 0;
}

Output of the above code:


Related Solutions

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
Please, write a loop to print odd numbers an array a with pointers backwards. You can...
Please, write a loop to print odd numbers an array a with pointers backwards. You can use a variable “size” for array size.
In C Create a multi-dimensional array and print it out forwards, backwards and then transpose.
In C Create a multi-dimensional array and print it out forwards, backwards and then transpose.
(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...
Initialize and Print an Array Write a program that accepts two integer values, called "arraySize" and...
Initialize and Print an Array Write a program that accepts two integer values, called "arraySize" and "multiplier", as user input. Create an array of integers with arraySize elements. Set each array element to the value i*multiplier, where i is the element's index. Next create two functions, called PrintForward() and PrintBackward(), that each accept two parameters: (a) the array to print, (b) the size of the array. The PrintForward() function should print each integer in the array, beginning with index 0....
Question 1 Please, write a loop to print even members of an array a with pointers....
Question 1 Please, write a loop to print even members of an array a with pointers. You can use a variable “size” for array size Example Input: 1,2,5,6,8,9 Output : 2,6,8 Question 6 Please, write a loop to print odd numbers an array a with pointers backwards. You can use a variable “size” for array size Example Input: 1,2,5,6,8,9 Output : 9,5, Question2 1 LINKED LIST QUESTIONS For the following two questions you need to provide a code in C...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array and remove the duplicates in-place such that each element appears only once in the input array and returns the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Find the time complexity of your removeDuplicates() method in Big-O notation and write that in a comment line on the top...
import math print("RSA ENCRYPTION/DECRYPTION") print("*****************************************************") #Input Prime Numbers print("PLEASE ENTER THE 'p' AND 'q' VALUES BELOW:")...
import math print("RSA ENCRYPTION/DECRYPTION") print("*****************************************************") #Input Prime Numbers print("PLEASE ENTER THE 'p' AND 'q' VALUES BELOW:") p = int(input("Enter a prime number for p: ")) q = int(input("Enter a prime number for q: ")) print("*****************************************************") #Check if Input's are Prime '''THIS FUNCTION AND THE CODE IMMEDIATELY BELOW THE FUNCTION CHECKS WHETHER THE INPUTS ARE PRIME OR NOT.''' def prime_check(a): if(a==2): return True elif((a<2) or ((a%2)==0)): return False elif(a>2): for i in range(2,a): if not(a%i): return false return True check_p =...
Write, specify and prove the function copy that copies a range of values into another array,...
Write, specify and prove the function copy that copies a range of values into another array, starting from the first cell of the array. First consider (and specify) that the two ranges are entirely separated. Note: Prototype is as below. void copy(int const* src, int* dst, size_t len){ }
Using Python : Create a 4×5 4 × 5 array ? X with random value. Print...
Using Python : Create a 4×5 4 × 5 array ? X with random value. Print out ? X , as well as the largest value of each column.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT