Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define DIM 100
  4. void leggi(char nomefile[], float matrice[][DIM], int *r, int*c);
  5. float elabora(float matrice[][DIM], int r, int c);
  6.  
  7. /*
  8. *
  9. */
  10. int main(int argc, char** argv) {
  11. char nomefile[DIM];
  12. float n;
  13. int r, c;
  14. float matrice[DIM][DIM];
  15.  
  16.  
  17.  
  18. printf("inserisci il nome del file da aprire:");
  19. scanf("%s", nomefile);
  20.  
  21.  
  22. leggi(nomefile, matrice, &r, &c);
  23.  
  24. n = elabora(matrice, r, c);
  25.  
  26. printf("il valore minimo è:%f", n);
  27. return (EXIT_SUCCESS);
  28. }
  29.  
  30. void leggi(char nomefile[], float matrice[][DIM], int *r, int *c) {
  31. FILE *fpin;
  32. int i, j;
  33.  
  34.  
  35. fpin = fopen(nomefile, "r");
  36. if (fpin == NULL) {
  37. printf("errore nell' apertura del file %s", nomefile);
  38. exit(1);
  39. } else {
  40. fscanf(fpin, "%d%d", r, c);
  41. printf("Le righe sono %d e le colonne sono %d\n", *r, *c);
  42. for (i = 0; i<*r; i++) {
  43. for (j = 0; j<*c; j++) {
  44. fscanf(fpin, "%f", &matrice[i][j]);
  45. }
  46. }
  47. }
  48.  
  49. }
  50.  
  51. float elabora(float matrice[][DIM], int r, int c) {
  52. int i, j;
  53. float s = 0;
  54. float vettsomme[DIM];
  55. float max,min;
  56.  
  57.  
  58. for (j = 0; j < c; j++) {
  59. for (i = 0; i < r; i++) {
  60. s = s + matrice[i][j];
  61. printf("%f\t", s);
  62. }
  63. vettsomme[j]=s;
  64. printf("%f\t", vettsomme[j]);
  65. s=0;
  66. }
  67.  
  68.  
  69.  
  70.  
  71. max=vettsomme[0];
  72. for(j=1;j<c;j++){
  73. if(vettsomme[j]>max){
  74. max=vettsomme[j];
  75. i=j;
  76. }
  77.  
  78. }
  79. j=i;
  80. min=matrice[0][j];
  81. for(i=0;i<r;i++){
  82. if(matrice[i][j]<min){
  83. min=matrice[i][j];
  84. }
  85. }
  86. printf("la somma max è %f\t", max);
  87.  
  88. return min;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement