Advertisement
Kimossab

IP - Exame 2015

Jan 22nd, 2015
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. //1
  2. //a) Vai dar erro por nao criar a variavel j
  3. //9%3 == 0  | x = 9
  4. //8%3 == 2  | j = 8
  5. //7%3 == 1  | x = 9
  6. // i = 1
  7. //7%3 == 1 | x = 7
  8. //i = 2
  9.  
  10. //b) erro, a e b nao criado
  11. //b = 4
  12. //b = 6
  13. //b = 7
  14. //b = 9
  15. //a = 4
  16.  
  17. //b = 6
  18. //b = 7
  19. //b = 9
  20. //a = 6
  21.  
  22. //b = 8
  23. //a = 8
  24.  
  25. //c)
  26. //x = 24 | y = 4
  27.  
  28. //2
  29. int Multiplos(int n, int m)
  30. {
  31.     printf("%d múltiplos de %d:\n",n,m);
  32.     for(int i=0; i<n; i++)
  33.         printf("[%d]",m*i);
  34. }
  35.  
  36. //3
  37. int Traco(int *mat, int elem)
  38. {
  39.     int soma=0;
  40.     for(int i=0; i<elem; i++)
  41.         soma+=*(mat+(i+i*elem));
  42.     return soma;
  43. }
  44.  
  45. //4
  46. //a)
  47. typedef struct
  48. {
  49.     char nome[60];
  50.     int nota;
  51.     int numerofaltas;
  52. }ALUNO;
  53. ALUNO turma[30];
  54.  
  55. //b)
  56. int InicTurma()
  57. {
  58.     int n;
  59.     printf("Insira o numero de alunos (máximo 30): ");
  60.     while(scanf("%d", &n) != 1 || n > 30 || n < 0)
  61.         printf("Insira o numero de alunos (máximo 30): ");
  62.     for(int i=0; i<n; i++)
  63.     {
  64.         printf("\nNome: ");
  65.         scanf("%s", turma[i].nome);
  66.         printf("\nNota: ");
  67.         scanf("%d", &turma[i].nota);
  68.         printf("\nNumero de Faltas: ");
  69.         scanf("%d", &turma[i].numerofaltas);
  70.     }
  71.     return n;
  72. }
  73.  
  74. //c)
  75. int Aprovados(int n)
  76. {
  77.     int ap=0;
  78.     printf("Alunos aprovados:\n");
  79.     for(int i=0; i<n; i++)
  80.         if(turma[i].nota > 9.5 && turma[i].numerofaltas < 4)
  81.         {
  82.             printf("%s\n", turma[i].nome);
  83.             ap++;
  84.         }
  85.     return ap;
  86. }
  87.  
  88. //5
  89. float LaSoma(int N)
  90. {
  91.     if(N == 1)
  92.         return 1/3;
  93.     return LaSoma(N-1)+1/(3*N);
  94. }
  95.  
  96. //6
  97. int TamFile(char *nome)
  98. {
  99.     int size;
  100.     FILE *f = fopen(nome, "rb");
  101.     if(!f) return 0;
  102.     fseek(f, 0, SEEK_END);
  103.     size = ftell(f);
  104.     fclose(f);
  105.     return size;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement