Question

Implement a function called rightrotate(int src[4][4], int dst[4][4]) that rotates the values in the src array...

Implement a function called rightrotate(int src[4][4], int dst[4][4]) that rotates the values in the src array 90 degrees to the left and stores it in the dst array. (See example below). Save your program in a file called Q4.cpp and save it in Question #4. YOU MUST USE LOOPS FOR THIS QUESTION!

src

1,2,3,4

5,6,7,8

9,0,1,2

3,4,5,6

dst

4,8,2,6

3,7,1,5

2,6,0,4

1,5,9,3

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream> #include <cmath> using namespace std; void rightrotate( int scr[][4] , int dist[4][4]){ for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { dist[i][j] = scr[j][4-i-1]; } } } void print_arr(int dist[4][4] ) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { cout << dist[i][j] << " "; } cout << endl; } } int main() { int scr[4][4]= { 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6}; int dist[4][4]; rightrotate( scr, dist ); print_arr(dist); }

4 8 2 6 3 7 1 5 26 04 1 5 9 3 Process finished with exit code o#include <iostream> using namespace std; void rightrotate( int scr[][4], int dist[4][4]){ for (int i = 0; i < 4; ++i) { for (

Add a comment
Know the answer?
Add Answer to:
Implement a function called rightrotate(int src[4][4], int dst[4][4]) that rotates the values in the src array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following matrix transpose routines: typedef int array[4][4]; void transpose (array dst, array src) {...

    Consider the following matrix transpose routines: typedef int array[4][4]; void transpose (array dst, array src) {     int i, j;     for (i=0; i<4; i++) {    for (j=0; j<4; j++) {           dst[i][j] = src[i][j];    }     } } void transpose2 (array dst, array src) {     int i, j;     for (i=0; i<4; i++) {    for (j=0; j<4; j++) {           dst[j][i] = src[j][i];    }     } } Assume this code runs on...

  • A method called linearSearch(), which takes as parameters an array of int followed by three values...

    A method called linearSearch(), which takes as parameters an array of int followed by three values of type int, and returns a value of type int. The first int parameter represents a key, the second int parameter represents a starting position, and the third int parameter represents an end position. If the key occurs in the array between the start position (inclusive) and the end position (exclusive), the method returns the position of the first occurrence of the key in...

  • Write another function called checkdiag2 (int checkdiag2 (int matrix[][100], int size)) that will return 1 if...

    Write another function called checkdiag2 (int checkdiag2 (int matrix[][100], int size)) that will return 1 if all the numbers on the antidiagonal are the same and 0 otherwise. Rewrite your main program to use 2D dynamic allocation instead for your array. Your array will have rows and columns depending of the first integer read from the file. Call your function from the main program. A typical report would look like The matrix is 8x8 and all the numbers on the...

  • Trying to do this in C++ Question 1: 1. Implement the function: int minInArray (int arr[],...

    Trying to do this in C++ Question 1: 1. Implement the function: int minInArray (int arr[], int arrSize) This function is given arr, an array of integers, and its logical size, arrSize. When called, t returns the minimum value in arr. Write a program that reads from the user a sequence of 20 integers (unnecessarily different from one another) into an array, and outputs the minimum value, and all the indices it appears in the array. 2. Your program should...

  • Question 1 In the following incomplete C program: #include stdlib.h> #include <stdio.h> int main () { int i, n, max; int array[100]; ... } return 0; } an array of random int values is populat...

    Question 1 In the following incomplete C program: #include stdlib.h> #include <stdio.h> int main () { int i, n, max; int array[100]; ... } return 0; } an array of random int values is populated with n random values. Write only the code to find the location of the maximum value in the array. Question 2 Follow these instructions in your Linux account: 1. Create a file called data.txt in the root folder in your account. 2. Create a new...

  • Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in...

    Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in one of two ways. In one method, the array elements are placed in a list enclosed in curly braces after the array name definition. For example, the code below creates an array of ints with 3 elements: 1, 2 and 3. int[] a = {1, 2, 3, 4}; We can also initialize an array with a new construct, indicating how many elements we want...

  • Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr,...

    Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr, int count, int key ) { 1: find the index of the first occurance of key. By first occurance we mean lowest index that contains this value. hint: copy the indexOf() method from Lab#3 into the bottom of this project file and call it from inside this remove method. The you will have the index of the value to remove from the array 2:...

  • Just Q3 and Q4 Q1] Write a C function to implement the binary search algorithm over...

    Just Q3 and Q4 Q1] Write a C function to implement the binary search algorithm over an array of integer numbers and size n. The function should return the index of the search key if the search key exists and return - 1 if the search key doesn't exist. [10 Points] Q2] Write a C function to implement the selection sort algorithm, to sort an array of float values and size n. The function should sort the array in ascending...

  • For C++ This is the information about the meal class 2-1. (24 marks) Define and implement...

    For C++ This is the information about the meal class 2-1. (24 marks) Define and implement a class named Dessert, which represents a special kind of Meal. It is to be defined by inheriting from the Meal class. The Dessert class has the following constructor: Dessert (string n, int co) // creates a meal with name n, whose type // is "dessert" and cost is co The class must have a private static attribute static int nextID ; which is...

  • QUESTION 5: Write a C++ function called layers which takes an NxN integer array (for some...

    QUESTION 5: Write a C++ function called layers which takes an NxN integer array (for some constant N) and populates the entries 0..N2-1 as follows: The upper left entry (row-0, col-0) is 0. Subsequent numbers are assigned along Southwest-to-Northeast diagonals, layer-by-layer. For example, if N=4, your function would result in the following assignment to entries in the array: 0 2 5 9 1 4 8 12 3 7 11 14 6 10 13 15 (the individual “layers” are shown by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT