Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. /* dichiara una matrice MxN, calcola la somma di tutti i valori, la somma
  2.  * dei valori della seconda colonna, la somma dei valori della terza colonna
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. /* definiamo numero di righe e di colonne affinchè siano, rispettivamente, maggiori
  9.  * di 3 e di 2
  10.  */
  11.  
  12. #define RIGHE 4
  13. #define COLONNE 3
  14.  
  15. int main(int argc, char*argv[])
  16. {double matrice[RIGHE][COLONNE];
  17.  double somma;
  18.  somma = 0;
  19.  double somma2c;
  20.  somma2c = 0;
  21.  double somma3r;
  22.  somma3r = 0;
  23.  
  24.  for(double rig=0; rig < RIGHE; rig++)
  25.   {
  26.    for (double col=0; col < COLONNE; col++)
  27.    {
  28.     printf("inserire il valore matrice[%f][%f]= ", rig, col);
  29.     scanf("%f", &(matrice[rig][col]));
  30.    }
  31.   }
  32.  
  33.   printf("stampiamo i valori della matrice \n");
  34.   for(rig=0; rig<M; rig++){
  35.    printf("\n");
  36.    for(col=0; col<N; col++){
  37.     printf("%f", matrice[rig][col]);
  38.     somma=somma+matrice[rig][col];
  39.     }
  40.      
  41.      for(double col=2;) {
  42.       for(double rig<M; rig++)
  43.       somma2c=somma2c+matrice[rig][col]
  44.       }
  45.      
  46.        for(double rig=3;) {
  47.         for(double col<N; col++)
  48.         somma3r=somma3r+matrice[rig][col]
  49.         }
  50.          
  51.          printf("%f", somma);
  52.          printf("%f", somma2c);
  53.          printf("%f", somma3r);
  54.     exit (EXIT_SUCCESS);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement