Question

In: Computer Science

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.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#include<stdio.h>

int main(){

                //creating constants for storing array sizes (rows and columns)

                const int rows=5, cols=4;

                //creating a 2d array of rows x cols size

                int array[rows][cols];

                //a variable used to assign values to each cell

                int counter=1;

                //looping through each row

                for(int i=0;i<rows;i++){

                                //looping through each column

                                for(int j=0;j<cols;j++){

                                               //assigning current value of counter to current position

                                               array[i][j]=counter;

                                               //updating counter

                                               counter++;

                                }

                }

               

                //printing array forwards

                printf("Array in forwards\n");

                //looping through each row

                for(int i=0;i<rows;i++){

                                //looping through each column

                                for(int j=0;j<cols;j++){

                                               //printing element at current row and column

                                               printf("%2d ",array[i][j]);

                                }

                                printf("\n");

                }

               

                //printing array backwards

                printf("\nArray in backwards\n");

                //looping through each row from last to first

                for(int i=rows-1;i>=0;i--){

                                //looping through each column from last to first

                                for(int j=cols-1;j>=0;j--){

                                               //printing element

                                               printf("%2d ",array[i][j]);

                                }

                                printf("\n");

                }

               

                //printing transpose

                printf("\nTranspose\n");

                //looping through each column

                for(int i=0;i<cols;i++){

                                //looping through each row

                                for(int j=0;j<rows;j++){

                                               printf("%2d ",array[j][i]);

                                }

                                printf("\n");

                }

                return 0;

}

/*OUTPUT*/

Array in forwards

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

17 18 19 20

Array in backwards

20 19 18 17

16 15 14 13

12 11 10 9

8 7 6 5

4 3 2 1

Transpose

1 5 9 13 17

2 6 10 14 18

3 7 11 15 19

4 8 12 16 20


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.
1. Create a PHP program containing an multi dimensional array of all the first and last...
1. Create a PHP program containing an multi dimensional array of all the first and last names of the students in your class. Sort the array by last name in alphabetic order. Also sort the array in reverse order. 2. Split the array from #1 into two arrays; one containing first names, the other containing last names.
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
In C++ for netbeans. Use a 1 dimensional array object to create a 2 dimensional table...
In C++ for netbeans. Use a 1 dimensional array object to create a 2 dimensional table object. Then modify to create a triangular table. Objective -> create an array of dynamic objects of RowAray inside Table i.e. an Aggregate. See Specs RowAray.h, Table.h Then create a triangular table, i.e. Triangle. Fill each cell with random 2 digit integers. The example Table has 8 columns of RowAray objects each filled with 6 rows of random 2 digit numbers. Then create a...
In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
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.
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.
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)        //...
in java Implement a function print2Darray(int[][] array) to print a formatted 4x4 two dimensional integer array....
in java Implement a function print2Darray(int[][] array) to print a formatted 4x4 two dimensional integer array. When the array contains {{10, 15, 30, 40},{15, 5, 8, 2}, {20, 2, 4, 2},{1, 4, 5, 0}}, Your output should look like: {10 15 30 40} {15 5 8 2}{ 20 2 4 2}{ 1450} Now, implement another function print2DList(ArrayList<ArrayList<Integer>> list) to print a formatted 2D list.
Build a two dimensional array out of the following three lists. The array will represent a...
Build a two dimensional array out of the following three lists. The array will represent a deck of cards. The values in dCardValues correspond to the card names in dCardNames. Note that when you make an array all data types must be the same. Apply dSuits to dCardValues and dCardNames by assigning a suit to each set of 13 elements. dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] dCardValues = ['2','3','4','5','6','7','8','9','10','11','12','13','14'] dSuits = ["Clubs","Spades","Diamonds","Hearts"] Once assigned your two dimensional array should resemble this : 2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT