Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SIZE 30
- void readFromFile(double myArr[][SIZE])
- {
- int r , c;
- FILE *inpFunc;
- inpFunc = fopen("matrix.txt","r");
- for ( r= 0; r <7 ; r++)
- for (c = 0; c < 4; c++)
- fscanf(inpFunc,"%lf",&myArr[r][c]);
- }
- void display(double myArr[][SIZE])
- {
- int r, c;
- for (r = 0; r < 7; r++)
- {
- for (c = 0; c < 4; c++)
- {
- printf("%.1lf ", myArr[r][c]);
- }
- printf("\n");
- }
- }
- int main(void)
- {
- double myArr[SIZE][SIZE],swapArr[SIZE];
- int num1, num2,r,c;
- readFromFile(myArr);
- display(myArr);
- do
- {
- printf("Enter two row indices to swap: ");
- scanf("%d %d", &num1, &num2);
- } while ( !(num1>=0 && num1<7 && num2>=0 && num2<7) );
- for (r = 0; r < 4; r++)
- {
- swapArr[r] = myArr[num1][r];
- }
- for (r = 0; r < 4; r++)
- {
- myArr[num1][r] = myArr[num2][r];
- }
- for (r = 0; r < 4; r++)
- {
- myArr[num2][r] = swapArr[r];
- }
- printf("\n");
- printf("\nThe contents of the array AFTER the swap operation\n");
- display(myArr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement