top of page

#include <stdio.h>

void take_data(int a[][10], int row,int column);

void menu();

void rowOperation(int array[][10],int row,int column,int r1,int r2);

void columnOperation(int array[][10],int row,int column,int c1,int c2);

int main() {

int array[10][10],column,row,i,j,r1,r2,c1,c2,choise=0;

 

printf("Enter size of array (max:10x10):\n");

    scanf("%d%d", &row, &column);

    take_data(array,row,column);

    printf("\nArray you entered is :\n");

for(i=0;i<row;i++){

for(j=0;j<column;j++){

printf("%2d",array[i][j]);

}

printf("\n");

}

 

while(choise!=3){

menu();

scanf("%d",&choise);

switch(choise){

case 1:printf("\nEnter two rows to exchange :");

scanf("%d%d",&r1,&r2);

rowOperation(array,row,column,r1,r2);

break;

case 2:printf("\nEnter two columns to exchange :");

scanf("%d%d",&c1,&c2);

columnOperation(array,row,column,c1,c2);

break;

case 3:printf("\nProgram was terminated successfully!!");break;

default :printf("\nWrOnG cHoIsE\n");

}

}

 

return 0;

}

void take_data(int a[][10],int row,int column){

    int i,j;

    printf("\nEnter elements of array:\n");

    for(i=0; i<row; ++i){

    for(j=0; j<column; ++j){

scanf("%d",&a[i][j]);

}

}

}

void menu(){

printf("\n********MaKe YoUr ChOiSe********\n");

printf("1)Exchange two rows\n2)Exchange two columns\n3)Exit");

}

void rowOperation(int array[][10],int row,int column,int r1,int r2){

int i,j;

for(i=0;i<row;i++){

int temp;

temp = array[r2][i];

array[r2][i] = array[r1][i];

array[r1][i] = temp;

}

 

printf("\nNew Array is :\n");

for(i=0;i<row;i++){

for(j=0;j<column;j++){

printf("%2d",array[i][j]);

}

   printf("\n");

}

}

 

void columnOperation(int array[][10],int row,int column,int c1,int c2){

int i,j;

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

int temp;

temp = array[i][c2];

array[i][c2] = array[i][c1];

array[i][c1] = temp;

}

 

printf("New Array is :\n");

for(i=0;i<row;i++){

for(j=0;j<column;j++){

printf("%2d",array[i][j]);

}

   printf("\n");

}

 

}

 

bottom of page