C Programing Practice 8- Two Dimensional Array Rotation For this assignment your
ID: 3587060 • Letter: C
Question
C Programing Practice 8- Two Dimensional Array Rotation
For this assignment your program should successfully rotate a Two Dimensional Array using C. Make sure to follow the guidelines below:
I) Create a Two Dimensional Array and enter the following string: “XOXXOXOXXOOXXOOX” Your array should look something like this when printing out:
X O X X
O X O X
X O O X
X O O X
II) Once you have set up your Array, now you will begin to rotate -90 degrees to the left.
III)Use multiple functions to organgize your program. Have main function call another function that does the rotation.
IIII) You will continue to rotate and print out your Array until you end up with what you started with.
EXAMPLE-
C Progranning: $ ./practice8_2DArray My Array- X 0 0 X First Rotation- X 0 0 0 0 X 0 Second Rotation- X 0 0 X X 0 0 X Third Rotation 0 0 X 0 0 0X Last Rotation (What you started with)Explanation / Answer
#include <stdio.h>
int main(void) {
char array[4][4] = {{'X','O','X','X'},{'O','X','O','X'},{'X','O','O','X'},{'X','O','O','X'}};
int i,j;
printf(" My Array ");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf(" %c ",array[i][j]);
}
printf(" ");
}
printf("First Rotation ");
for(i=3;i>=0;i--)
{
for(j=0;j<4;j++)
{
printf(" %c ",array[j][i]);
}
printf(" ");
}
printf("Second Rotation ");
for(i=3;i>=0;i--)
{
for(j=3;j>=0;j--)
{
printf(" %c ",array[i][j]);
}
printf(" ");
}
printf("Third Rotation ");
for(i=0;i<4;i++)
{
for(j=3;j>=0;j--)
{
printf(" %c ",array[j][i]);
}
printf(" ");
}
printf(" Last Rotation ");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf(" %c ",array[i][j]);
}
printf(" ");
}
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.