Hey, this code accepts data (type int) into a 4 by 4 array. im using 1234 as an example
when entered, the data would be stored as:
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
the code the rotates it once to the right so it is printed out as:
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
it was an example my teacher gave us to practice manipulating data in 2D arrays.
i dont fully understand how it works, could someone explain to me step by step how it works?
#include<stdio.h>
main(){
int i,j,pass;
int row=4;
int col=4;
int arr[4][4],barr[4][4];
char abc;
//prompt user to enter numbers to store in arr
for(i=0;i<row;i++)
for(j=0;j<col;j++){
printf("Enter a number ");
scanf("%d",&arr[i][j]);
}
pass=row-1;
for(i=0;i<row;i++){
for(j=0;j<col;j++)
barr[j][pass]=arr[i][j];
pass=pass-1;
}
for(i=0;i<row;i++){
for(j=0;j<col;j++)
printf("%d ",barr[i][j]);
printf("\n");
}
scanf ("%ch", &abc); //keeps data on screen
return(0);
}
thanks in advance. oh and could someone possibly explain how i would manipulate to print out the array rotate it more times to the right?