Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #define SIZE 30
  3.  
  4. void readFromFile(double myArr[][SIZE])
  5. {
  6. int r , c;
  7. FILE *inpFunc;
  8. inpFunc = fopen("matrix.txt","r");
  9.  
  10. for ( r= 0; r <7 ; r++)
  11. for (c = 0; c < 4; c++)
  12. fscanf(inpFunc,"%lf",&myArr[r][c]);
  13.  
  14. }
  15.  
  16. void display(double myArr[][SIZE])
  17. {
  18. int r, c;
  19.  
  20. for (r = 0; r < 7; r++)
  21. {
  22. for (c = 0; c < 4; c++)
  23. {
  24. printf("%.1lf ", myArr[r][c]);
  25. }
  26. printf("\n");
  27. }
  28. }
  29.  
  30. int main(void)
  31. {
  32.  
  33. double myArr[SIZE][SIZE],swapArr[SIZE];
  34. int num1, num2,r,c;
  35. readFromFile(myArr);
  36. display(myArr);
  37.  
  38. do
  39. {
  40. printf("Enter two row indices to swap: ");
  41. scanf("%d %d", &num1, &num2);
  42. } while ( !(num1>=0 && num1<7 && num2>=0 && num2<7) );
  43.  
  44. for (r = 0; r < 4; r++)
  45. {
  46. swapArr[r] = myArr[num1][r];
  47.  
  48. }
  49.  
  50. for (r = 0; r < 4; r++)
  51. {
  52. myArr[num1][r] = myArr[num2][r];
  53. }
  54. for (r = 0; r < 4; r++)
  55. {
  56. myArr[num2][r] = swapArr[r];
  57. }
  58.  
  59.  
  60. printf("\n");
  61. printf("\nThe contents of the array AFTER the swap operation\n");
  62. display(myArr);
  63.  
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement