Advertisement
Smokahontas

Exercicios0505

May 5th, 2024 (edited)
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. Exercicio 1:
  2. Resposta correta : (A)
  3.  
  4. Código:
  5. 1. for (i = 0 to 29) {
  6. 2.   for (j = 0 to 39) {
  7. 3.     if (a[i] == b[j]) {
  8. 4.       print(a[i]);
  9. 5.     }
  10. 6.   }
  11. 7. }
  12.  
  13.  
  14. ////////////////////////////////////////////
  15.  
  16. Exercicio 2:
  17. 3. if (a[i] == b[j]) {
  18.  
  19. 4.       print (a[i]);
  20.  
  21. 5. }
  22.  
  23. ////////////////////////////////////////////
  24.  
  25. Exercicio 3:
  26.  
  27. Cálculo feito:
  28. -a * b++ - c--
  29. = -1 * 2++ - 0--
  30. = -2 - 0
  31. = -2
  32.  
  33. Então, o resultado da expressão -a * b++ - c-- é -2, correspondendo à opção (E).
  34.  
  35. ////////////////////////////////////////////
  36.  
  37. EXERCICIO 4:
  38.  
  39. A: A melhor opção para este problema é uma matriz. por ser uma tabela organizada em linhas e colunas, ideal para representar a plantação de café.
  40.  
  41.  
  42. B:
  43. int contarFalhasPlantio(int matriz[3][5], int linhas, int colunas) {
  44.     int falhas = 0;
  45.     for (int linha = 0; linha < linhas; linha++) {
  46.         for (int coluna = 0; coluna < colunas; coluna++) {
  47.             if (matriz[linha][coluna] == 0) {
  48.                 falhas++;
  49.             }
  50.         }
  51.     }
  52.     return falhas;
  53. }
  54.  
  55. int main() {
  56.    
  57.     int plantacao[3][5] = {
  58.         {1, 0, 1, 0, 0},
  59.         {0, 1, 0, 1, 0},
  60.         {1, 0, 0, 0, 1}
  61.     };
  62.  
  63.     int linhas = 3;
  64.     int colunas = 5;
  65.  
  66.     int totalFalhas = contarFalhasPlantio(plantacao, linhas, colunas);
  67.     printf("Total de falhas de plantio: %d\n", totalFalhas);
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement