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 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.
IN JAVA - [(1)] A palindrome is a string that reads the same forwards as backwards....
IN JAVA - [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q be a non-empty...
How to create a two-dimensional array, initializing elements in the array and access an element in...
How to create a two-dimensional array, initializing elements in the array and access an element in the array using PHP, C# and Python? Provide code examples for each of these programming languages. [10pt] PHP C# Python Create a two-dimensional array Initializing elements in the array Access an element in the array
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...
python question A word is a palindrome if it the same read forwards and backwards. We...
python question A word is a palindrome if it the same read forwards and backwards. We will call a word a fuzzy palindrome if it is the same read forwards and backwards, except for possible differences in case. For example, both 'tattarrattat' and 'TaTtArRAttat' are fuzzy palindromes. Define a function is_fuzzy_palindrome that returns True if and only if its argument is a fuzzy palindrome. This method may be useful: S.lower() -> str : Return a copy of the string S...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT