Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. /* D'Ottavi Fabio esercizio 3 lezione 2, creare una matrice e fare somma totale, somma della seconda colonna e della terza riga*/
  2.  
  3. #include <stdio.h>  
  4. #include <stdlib.h>
  5. #define N 4
  6. #define M 3
  7.  
  8. int main (int argc, char * argv[])
  9. {
  10.     int i, j;
  11.     double sum, mat[N][M];
  12.     for(i=0;i<N;i++)
  13.     {
  14.         for(j=0;j<M;j++)
  15.         {
  16.             printf("ingresso [%d][%d]: ",i,j);
  17.             scanf("%lf", &mat[i][j]);
  18.         }
  19.     }
  20.     for(i=0;i<N;i++)
  21.     {
  22.         for(j=0;j<M;j++)
  23.         {
  24.             printf("%lf  ", mat[i][j]);
  25.         }
  26.         printf("\n");
  27.     }
  28.     sum=0;
  29.     for(i=0;i<N;i++)
  30.     {
  31.         for(j=0;j<M;j++)
  32.         {
  33.             sum=sum+mat[i][j];
  34.         }
  35.     }
  36.     printf("somma totale: %lf \n", sum);
  37.     sum=0;
  38.     for (i=0;i<N;i++)
  39.     {
  40.         sum=sum+mat[i][1];
  41.     }  
  42.     printf("somma della seconda colonna è: %lf \n", sum);
  43.     sum=0;
  44.     for (j=0;j<M;j++)
  45.     {
  46.         sum=sum+mat[2][j];
  47.     }  
  48.     printf("somma della terza riga è: %lf \n", sum);  
  49.        
  50.     exit (EXIT_SUCCESS);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement