Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "funzioni.h"
  4.  
  5.  
  6. int leggiMatrice (matrice m, int&r, int&c)
  7. {
  8. fstream f0;
  9. r=0; c=0;
  10. f0.open("file iniziale.txt", ios::in);
  11. f0>>r; cout<<"la matrice ha "<<r<<" righe\n";
  12. f0>>c; cout<<"la matrice ha "<<c<<" colonne\n";
  13. for (int i=0; i<r;i++)
  14. {
  15. cout<<"\n";
  16. for (int j=0;j<c;j++)
  17. {
  18. f0>>m[i][j];
  19. cout<<"["<<m[i][j]<<"] ";
  20. }
  21. }
  22. f0.close();
  23. }
  24.  
  25. int MAX (matrice m, int r, int c, int&max_i, int&max, int&max_j)
  26. {
  27. max=0;
  28. max_i=0;
  29. max_j=0;
  30. for (int i=0; i<r;i++)
  31. {
  32. for (int j=0;j<c;j++)
  33. {
  34. if (m[i][j]>max)
  35. {
  36. max=m[i][j];
  37. max_i=i;
  38. max_j=j;
  39. }
  40. }
  41. }
  42. cout<<"\n\nil massimo si trova nella riga numero "<<max_i<<" e nella colonna numero "<<max_j<<"\n\n";
  43.  
  44.  
  45. }
  46.  
  47. int eliminaRiga (matrice m, int r, int c, int& max_i)
  48.  
  49. {
  50.  
  51. int i, j;
  52. if(max_i==r-1)
  53. {
  54. r--;
  55. }
  56. else
  57. {
  58. for(i=0;i<r;i++)
  59. {
  60. for(j=0;j<c-1;j++)
  61. {
  62. if(i>=max_i)
  63. {
  64. m[i][j]=m[i+1][j];
  65. }
  66. }
  67. }
  68. }
  69. }
  70.  
  71. int eliminaColonna (matrice m, int r, int c, int& max_j)
  72. {
  73. int i,j;
  74. if(max_j==c-1)
  75. {
  76. c--;
  77. }
  78. else
  79. {
  80. for(i=0;i<r;i++)
  81. {
  82. for (j=0;j<c-1;j++)
  83. {
  84. if (j>=max_j)
  85. {
  86. m[i][j]=m[i][j+1];
  87. }
  88. }
  89. }
  90. }
  91. }
  92.  
  93. int nuovaMatrice (matrice m, int r, int c)
  94. {
  95. fstream f1;
  96. int i, j;
  97. f1.open("f_output.txt", ios::out);
  98. for (i=0;i<r;i++)
  99. {
  100. f1<<"\n";
  101. cout<<"\n";
  102. for (j=0;j<c;j++)
  103. {
  104. f1<<"["<<m[i][j]<<"] ";
  105. cout<<"["<<m[i][j]<<"] ";
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement