Question

Assignment: Write a C function that accepts the pointer to a matrix of integer numbers (i.e. a two-dimensional array), number of rows and number of columns as input and prints the matrix after rotating it 90 degrees clockwise. Example: void rotate-matrix (int* matrix, int row, int column) Inputs: row 4, column-6 and the pointer to the matrix below: 2 3 6 5 8 0 Output:
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/* c program to rotate a matrix 90 degrees clock wise*/

void rotate_matrix( int *matrix,int row,int column);

int a[20][20];

int main()

{

int rows,columns,i,j;

clrscr();

printf("\n Enter the number of rows and columns of a matrix");

scanf("%d%d",&rows,&columns);

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

{

for(j=0;j<columns;j++)

{

scanf("%d",&a[i][j]); /* reading elements into matrix */

}

}

printf("\n Original matrix is \n");

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

{

for(j=0;j<columns;j++)

{

printf("%d\t",a[i][j]); /* reading elements into matrix */

}

printf("\n");

}

printf("\n Matrix after 90 degrees clock wise rotation\n");

rotate_matrix((int *)a,rows,columns);

getch();

return 0;

}

void rotate_matrix(int *matrix,int row,int column) /* logic to rotate 90 degrees clockwise */

{

int i,j;

for(i=0;i<column;i++)

{

for(j=row-1;j>=0;j--)

{

printf("%d\t",a[j][i]);

}

printf("\n");

}

}

Output:

Enter the number of rows and columns of a matrix4 0 1 3 6 3 1 2 3 6 5 8 0 7 4 8 6 2 1 3 4 6 2 1 6 Original matrix is 6 8 6 8 6 6 Matrix after 90 degrees clock wise rotation 8 6 5 8 6

Enter the number of rows and columns of a matrix4 0 1 3 6 3 1 2 3 6 5 8 0 7 4 8 6 2 1 3 4 6 2 1 6 Original matrix is 6 8 6 8 6 6 Matrix after 90 degrees clock wise rotation 8 6 5 8 6

Add a comment
Know the answer?
Add Answer to:
Assignment: Write a C function that accepts the pointer to a matrix of integer numbers (i.e....
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
  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

  • ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given....

    ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given. Perform various matrix processing activities according to the algorithms below. Store the results into the output vector (one-dimensional array) with appropriate size. For Grade 7) Count the number of odd values (n mod 2 <> 0) for each row. For Grade 9) Calculate the sum of positive values for each column. To obtain inputs and return the results, define appropriate type C/C++ functions. Please...

  • 1) Define a 2 dimensional arrays of doubles (3 rows by 3 columns) and 2) Read...

    1) Define a 2 dimensional arrays of doubles (3 rows by 3 columns) and 2) Read values from the user. 3) Print the numbers entered by the user in row major order 4) Print the numbers entered by the user in column major order import java.util.*; public class XXX_Chapter83 { public static void main(String[] args) { //creates array and stores values with input from user printArrayRowMajor (board); printArrayColumnMajor (board); } public static void printArrayRowMajor (int [] [] board) { //prints...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • convert the for loop into x86 assembly..             int[][] rotateMatrixBy90Degree(int[][] matrix, int n) { //We need...

    convert the for loop into x86 assembly..             int[][] rotateMatrixBy90Degree(int[][] matrix, int n) { //We need to run the loop for only half the number of rows as it represents one quarter or quadrant for (int layer = 0; layer < n / 2; layer++) { //In every iteration, we reduce number of columns to be swapped by computing first and last column index. We are rotating counter clockwise.                                     int first = layer; //start column pixel of current row...

  • Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of...

    Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of integers in which each row has three columns the number of rows in the array function  f returns the sum of the odd integers in the given array of integers and returns zero if there are no odd integers in the array COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None COMPILER COMMAND LINE ARGUMENTS -lm INPUT OF THE TEST CASE 1 #define NUM_ROWS 5...

  • Preferred in Java Write a method called print Array With Total that accepts a reference to...

    Preferred in Java Write a method called print Array With Total that accepts a reference to a two - dimensional array of integers and two primitive integers called number Of Rows and number OF Columns as parameters and displays the elements of two - dimensional array as a table with an extra column for the row total as the rightmost column and an extra row for the column totals as the bottom row. (Please do NOT call either definition of...

  • Write a Java program that calculates the sum of a variable sized matrix using a two...

    Write a Java program that calculates the sum of a variable sized matrix using a two dimensional array. (ArraySum.java) The user should provide the number of rows and columns Test multiple user inputs (3 times 2, 4 times 4, 6 times 2, etc) A sum should be created for each row, each column, and the total for the matrix Ex.: How big would you like your matrix? Rows - ? 3 Columns -? 2 Please enter your row 1? Column...

  • C++ Vectors readImage: Creates a two dimensional vector (a matrix) of 1's and 0's based off...

    C++ Vectors readImage: Creates a two dimensional vector (a matrix) of 1's and 0's based off of the input files which you send it. (Returns a multidimensional vector). Take two inputs - number of columns and number of rows.The image stored in a two-dimensional vector of ints. printImage: Takes the matrix which was created in readImage and prints it out. vector <vector<int>> readImage(int,int); void printImage (vector<vector<int>>); input: (explained in ()'s ) 1 -(input 1) 10 1 - (10 colums and...

  • Java Here is the template public class ShiftNumbers { public static void main(String[] args) { // TODO:...

    Java Here is the template public class ShiftNumbers { public static void main(String[] args) { // TODO: Declare matrix shell size // TODO: Create first row // TODO: Generate remaining rows // TODO: Display matrix } /** * firstRow * * This will generate the first row of the matrix, given the size n. The * elements of this row will be the values from 1 to n * * @param size int Desired size of the array * @return...

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
ADVERTISEMENT