!-- inicio configuracao do Syntax Highlighting -->

sábado, 29 de junho de 2013

Utilizando funções registros, crie um programa que leia nome e idade de cinco alunos. Exiba o nome do aluno mais velho e a idade do aluno mais novo.

Utilizando funcoes e registros, crie um programa que leia nome e idade de cinco alunos. Exiba o nome do aluno mais velho e a idade do aluno mais novo. English Using functions and records, create a program that reads the name and age of five students. Display the name of the oldest student and the age of the younger student.

 

#include 
#include 
#include 

/*

*/

struct TAluno{
    char nome [45];
    int idade;
};


TAluno lerAluno(){
      TAluno r;
     
      //preencher r;
      printf("======== Novo Aluno =========\n");
      printf("nome:");
      scanf("%s", &r.nome);
      printf("idade:");
      scanf("%i", &r.idade);
     
      return r;
}

void imprimir(TAluno a){
    printf("-----------------------\n");
    printf("nome: %s\n", a.nome);
    printf("Idade: %i\n", a.idade);
    printf("-----------------------\n");
}

main(){
    TAluno vet [5];
    for(int i=0; i<5; i++){
         vet[i] = lerAluno();
    }
   
    TAluno maisVelho = vet[0];
    TAluno maisNovo = vet[0];
   
    for(int i=1; i<5; i++){
         //imprimir(vet[i]);
         if(vet[i].idade > maisVelho.idade){
              maisVelho = vet[i];
             
         }
         if(vet[i].idade < maisNovo.idade){
              maisNovo = vet[i];
         }
    }
   
    printf("-----------------------\n");
    printf("nome do + velho: %s\n", maisVelho.nome);
    printf("Idade do + novo: %i\n", maisNovo.idade);
    printf("-----------------------\n");
   
    getch();
}

0 comentários:

Postar um comentário

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More