Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct Panda
- {
- char *nombrep;
- float peso;
- int anonac;
- char sexo;
- }mip;
- void LeerPanda(mip *p);
- int EdadPanda(mip p);
- int TenerBebes(mip p);
- void main()
- {
- mip mp;
- int puede;
- LeerPanda(&mp);
- puede=TenerBebes(mp);
- if (puede==1)
- printf("El panda %s puede tener bebes\n", mp.nombrep);
- else
- {
- printf("El panda %s no puede tener bebes\n", mp.nombrep);
- }
- }
- void LeerPanda(mip *p)
- {
- char nom[35];
- printf("El panda se llama: ");
- gets(nom);
- p->nombrep=(char *)malloc(sizeof(char) * strlen(nom)+1);
- if(p==NULL)
- {
- printf("Insuficiente espacio de memoria\n");
- exit(1);
- }
- strcpy(p->nombrep, nom);
- fflush(stdin);
- printf("Su peso es: ");
- scanf("%f", &p->peso);
- fflush(stdin);
- printf("Su año de nacimiento es: ");
- scanf("%d", &p->anonac);
- fflush(stdin);
- printf("Su sexo es: ");
- scanf("%c", &p->sexo);
- }
- int EdadPanda(mip p)
- {
- int edadp;
- edadp=2018-p.anonac;
- return(edadp);
- }
- int TenerBebes(mip p)
- {
- int res, edad;
- edad=EdadPanda(p);
- if (edad>=5 && (p.sexo=='f' || p.sexo=='F'))
- res=1;
- else
- {
- res=0;
- }
- return(res);
- }
Advertisement
Add Comment
Please, Sign In to add comment