Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int fill(int rows,int cols,int arr[rows][cols]){
- for(int i=0;i<rows;i++){
- for(int j=0;j<cols;j++){
- printf("Fill the indicie %dx%d\n",i ,j);
- scanf("%d", &arr[i][j]);
- }
- }
- int userchoice=choice();
- if(userchoice == 1)
- rowswap(rows,cols,arr);
- else
- colswap(rows,cols,arr);
- }
- int choice(){
- int choice=0;
- do{
- puts("1 to swap rows");
- puts("2 to swap cols");
- scanf("%d", &choice);
- }
- while(choice != 1 && choice !=2);
- return choice;
- }
- void colswap(int rows,int cols, int arr[rows][cols]){
- puts("PreSwap");
- for(int i=0;i<rows;i++){
- for(int j=0;j<cols;j++){
- printf("%d ", arr[i][j]);
- }
- puts(""); }
- int swap1,swap2;
- printf("Enter two cols to swap 0-%d", cols-1);
- scanf("%d%d", &swap1, &swap2);
- for(int j=0;j<rows;j++){
- int temp=arr[j][swap1];
- arr[j][swap1] = arr[j][swap2];
- arr[j][swap2] = temp;
- }
- for(int m=0;m<rows;m++){
- for(int n=0;n<cols;n++){
- printf("%d ", arr[m][n]);
- }
- puts("");}
- char str[5] = "cols";
- char newstr[5];
- int k=0;
- puts("Enter ""cols"" if you want to swap rows, exit to end program");
- scanf("%s", newstr);
- for(int i=0;i<4;i++){
- if(str[i]==newstr[i])
- k++;
- }
- if(k==4)
- rowswap(rows, cols, arr);
- else
- return 0;
- }
- int rowswap(int rows, int cols, int arr[rows][cols]){
- puts("PreSwap");
- for(int a=0; a<rows;a++){
- for(int b=0;b<cols;b++){
- printf("%d ", arr[a][b]);
- }
- puts("");
- }
- puts("");
- printf("Enter two rows to swap 0-%d\n", rows-1);
- int swap1, swap2;
- scanf("%d%d", &swap1,&swap2);
- for(int i =0;i<cols;i++){
- int temp = arr[swap1][i];
- arr[swap1][i] = arr[swap2][i];
- arr[swap2][i] = temp;
- }
- puts("PostSwap");
- for(int i=0;i<rows;i++){
- for(int j=0;j<cols;j++){
- printf("%d ", arr[i][j]);
- }
- puts("");
- }
- puts("Enter cols to swap cols, exit to end the program");
- int k=0;
- char str[5]= "cols";
- char strnew[5];
- scanf("%s", strnew);
- for(int w=0;w<4;w++){
- if(strnew[w]==str[w])
- k++;
- }
- if(k==4)
- colswap(rows,cols,arr);
- else
- return 0;
- }
- int main(){
- puts("Enter the dimenssions of the arr");
- int rows, cols;
- scanf("%d %d", &rows, &cols);
- int arr[rows][cols];
- fill(rows, cols, arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement