Created
April 19, 2017 11:05
-
-
Save manuwell/0bb3e504d3fccdb5b355ee4bd1204aa0 to your computer and use it in GitHub Desktop.
Anhembi - Construção Algoritmos - Atividade 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*H********************************************************************** | |
* FILENAME : main.c | |
* | |
* DESCRIPTION : | |
* Cadastro de pessoas com nome, idade e sexo e imprime as pessoas | |
* do sexo feminino com idade até 28 anos (inclusive) | |
* | |
* | |
* AUTHOR : Wellington Santos RA : 20993835 | |
* | |
* COMPILATION : gcc -o cadastro main.c | |
* | |
* EXECUTION: ./cadastro | |
* | |
* Have fun \o/ | |
*H*/ | |
#include <stdio.h> | |
#include <string.h> | |
typedef struct Person { | |
char name[100]; | |
char genre[1]; | |
int age; | |
} Person; | |
int MAX_SIZE = 40; | |
void printPerson(Person p){ | |
printf("Nome: %-20s Sexo: %-10s Idade: %2d \n", p.name, p.genre, p.age); | |
} | |
Person readPersonInfo(){ | |
Person p; | |
printf("Digite o nome:\n"); | |
scanf("%s", p.name); | |
printf("Digite o sexo (M: para masculino e F: feminino):\n"); | |
scanf("%s", p.genre); | |
printf("Digite a idade:\n"); | |
scanf("%d", &p.age); | |
return p; | |
} | |
int main(){ | |
Person persons[MAX_SIZE]; | |
int i; | |
// populate loop | |
for(i=0 ; i < MAX_SIZE ; i++){ | |
printf("\n\n== Cadastro da pessoa n%02d\n", (i+1)); | |
persons[i] = readPersonInfo(); | |
} | |
// print loop | |
printf("\n\n== Lista de pessoas do sexo F com idade até 28\n"); | |
for(i=0; i< MAX_SIZE; i++){ | |
Person p = persons[i]; | |
if(p.age <= 28 && strcmp("F", p.genre) == 0){ | |
printPerson(persons[i]); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment