Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* D'Ottavi Fabio esercizio 3 lezione 2, creare una matrice e fare somma totale, somma della seconda colonna e della terza riga*/
- #include <stdio.h>
- #include <stdlib.h>
- #define N 4
- #define M 3
- int main (int argc, char * argv[])
- {
- int i, j;
- double sum, mat[N][M];
- for(i=0;i<N;i++)
- {
- for(j=0;j<M;j++)
- {
- printf("ingresso [%d][%d]: ",i,j);
- scanf("%lf", &mat[i][j]);
- }
- }
- for(i=0;i<N;i++)
- {
- for(j=0;j<M;j++)
- {
- printf("%lf ", mat[i][j]);
- }
- printf("\n");
- }
- sum=0;
- for(i=0;i<N;i++)
- {
- for(j=0;j<M;j++)
- {
- sum=sum+mat[i][j];
- }
- }
- printf("somma totale: %lf \n", sum);
- sum=0;
- for (i=0;i<N;i++)
- {
- sum=sum+mat[i][1];
- }
- printf("somma della seconda colonna è: %lf \n", sum);
- sum=0;
- for (j=0;j<M;j++)
- {
- sum=sum+mat[2][j];
- }
- printf("somma della terza riga è: %lf \n", sum);
- exit (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement