fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define N_ALUNOS 5
  6.  
  7. typedef struct {
  8. char nome[25];
  9. int matricula;
  10. float notas[2];
  11. char situacao[10];
  12. } Aluno;
  13.  
  14. Aluno Alunos[N_ALUNOS];
  15.  
  16. int alunosCadastrados = 0;
  17.  
  18. void atualizaArray(int posExcluida){
  19. if(posExcluida >= 0 && posExcluida < alunosCadastrados - 1){
  20. for(int j = posExcluida; j < alunosCadastrados - 1; j++){
  21. Alunos[j].matricula = Alunos[j + 1].matricula;
  22. strcpy(Alunos[j].situacao, Alunos[j + 1].situacao);
  23. Alunos[j].notas[0] = Alunos[j + 1].notas[0];
  24. Alunos[j].notas[1] = Alunos[j + 1].notas[1];
  25. strcpy(Alunos[j].nome, Alunos[j + 1].nome);
  26. }
  27. alunosCadastrados--;
  28. }
  29. }
  30.  
  31. void mostrarAlunos(){
  32. for (int i = 0;i < alunosCadastrados;++i){
  33. printf("%d - %s, %d, %f, %f, %s\n", i, Alunos[i].nome, Alunos[i].matricula, Alunos[i].notas[0], Alunos[i].notas[1], Alunos[i].situacao);
  34. }
  35. }
  36.  
  37. void inserirAluno(char *nome, int matricula, float nota1, float nota2, char *situacao){
  38. strcpy(Alunos[alunosCadastrados].nome, nome);
  39. Alunos[alunosCadastrados].matricula = matricula;
  40. Alunos[alunosCadastrados].notas[0] = nota1;
  41. Alunos[alunosCadastrados].notas[1] = nota2;
  42. strcpy(Alunos[alunosCadastrados].situacao, situacao);
  43. alunosCadastrados++;
  44. }
  45.  
  46. int main() {
  47.  
  48. inserirAluno("Carlos", 1234, 10.0f, 12.0f, "aprovado");
  49. inserirAluno("Sofia", 5678, 19.0f, 14.0f, "aprovada");
  50. inserirAluno("Manuel", 4894, 7.0f, 9.0f, "reprovado");
  51. inserirAluno("Cristina", 9156, 5.0f, 11.0f, "reprovada");
  52. mostrarAlunos();
  53. printf("\nDepois da remover:\n");
  54.  
  55. atualizaArray(0);
  56. mostrarAlunos();
  57.  
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
0 - Carlos, 1234, 10.000000, 12.000000, aprovado
1 - Sofia, 5678, 19.000000, 14.000000, aprovada
2 - Manuel, 4894, 7.000000, 9.000000, reprovado
3 - Cristina, 9156, 5.000000, 11.000000, reprovada

Depois da remover:
0 - Sofia, 5678, 19.000000, 14.000000, aprovada
1 - Manuel, 4894, 7.000000, 9.000000, reprovado
2 - Cristina, 9156, 5.000000, 11.000000, reprovada