Page 1627 - Informatica dalla A a Z
P. 1627

#include <stdio.h>

              #include <stdbool.h>


              #define MAX_PACC 64


              typedef int TipoPacchetto[4];


              int main ()
              {
              TipoPacchetto corretti[MAX_PACC], non_corretti[MAX_PACC], cor-
              rente;
              int i, j, k, h, somma, n_corretti, n_non_corretti;
              bool ammissibile;


              i = 0; j = 0; k = 0;
              while(i < MAX_PACC)
              {
                  printf("Pacchetto numero %d (4 bit, separare i singoli bit
              con degli spazi): ",

                  i+1);
                  scanf("%d %d %d %d", &corrente[0], &corrente[1], &cor-
              rente[2], &corrente[3]);
                  ammissibile = true;
                  somma = 0;
                  for(h = 0 ; h < 4 ; h++)
                  {
                        if(corrente[h] > 1 || corrente[h] < 0)
                          {
                               ammissibile = false;
                          }
                          else
                          {
                               somma += corrente[h];
                          }
                  }
                  if (ammissibile)
                  {
                          if (somma % 2 == 0)
                          {
                               for(h = 0; h < 4; h++)
                               {
                                      corretti[j][h] = corrente[h];

                               }
                               j++;
                                                           1623
   1622   1623   1624   1625   1626   1627   1628   1629   1630   1631   1632