Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define DIM 100
- void leggi(char nomefile[], float matrice[][DIM], int *r, int*c);
- float elabora(float matrice[][DIM], int r, int c);
- /*
- *
- */
- int main(int argc, char** argv) {
- char nomefile[DIM];
- float n;
- int r, c;
- float matrice[DIM][DIM];
- printf("inserisci il nome del file da aprire:");
- scanf("%s", nomefile);
- leggi(nomefile, matrice, &r, &c);
- n = elabora(matrice, r, c);
- printf("il valore minimo è:%f", n);
- return (EXIT_SUCCESS);
- }
- void leggi(char nomefile[], float matrice[][DIM], int *r, int *c) {
- FILE *fpin;
- int i, j;
- fpin = fopen(nomefile, "r");
- if (fpin == NULL) {
- printf("errore nell' apertura del file %s", nomefile);
- exit(1);
- } else {
- fscanf(fpin, "%d%d", r, c);
- printf("Le righe sono %d e le colonne sono %d\n", *r, *c);
- for (i = 0; i<*r; i++) {
- for (j = 0; j<*c; j++) {
- fscanf(fpin, "%f", &matrice[i][j]);
- }
- }
- }
- }
- float elabora(float matrice[][DIM], int r, int c) {
- int i, j;
- float s = 0;
- float vettsomme[DIM];
- float max,min;
- for (j = 0; j < c; j++) {
- for (i = 0; i < r; i++) {
- s = s + matrice[i][j];
- printf("%f\t", s);
- }
- vettsomme[j]=s;
- printf("%f\t", vettsomme[j]);
- s=0;
- }
- max=vettsomme[0];
- for(j=1;j<c;j++){
- if(vettsomme[j]>max){
- max=vettsomme[j];
- i=j;
- }
- }
- j=i;
- min=matrice[0][j];
- for(i=0;i<r;i++){
- if(matrice[i][j]<min){
- min=matrice[i][j];
- }
- }
- printf("la somma max è %f\t", max);
- return min;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement