vacendak

Panda

Jul 17th, 2018
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct Panda
  6. {
  7.     char *nombrep;
  8.     float peso;
  9.     int anonac;
  10.     char sexo;
  11. }mip;
  12.  
  13. void LeerPanda(mip *p);
  14. int EdadPanda(mip p);
  15. int TenerBebes(mip p);
  16.  
  17.  
  18.  
  19. void main()
  20. {
  21.     mip mp;
  22.     int puede;
  23.  
  24.     LeerPanda(&mp);
  25.     puede=TenerBebes(mp);
  26.  
  27.     if (puede==1)
  28.         printf("El panda %s puede tener bebes\n", mp.nombrep);
  29.     else
  30.     {
  31.         printf("El panda %s no puede tener bebes\n", mp.nombrep);
  32.     }
  33. }
  34. void LeerPanda(mip *p)
  35.     {
  36.         char nom[35];
  37.  
  38.         printf("El panda se llama: ");
  39.         gets(nom);
  40.         p->nombrep=(char *)malloc(sizeof(char) * strlen(nom)+1);
  41.         if(p==NULL)
  42.         {
  43.             printf("Insuficiente espacio de memoria\n");
  44.             exit(1);
  45.         }
  46.         strcpy(p->nombrep, nom);
  47.         fflush(stdin);
  48.         printf("Su peso es: ");
  49.         scanf("%f", &p->peso);
  50.         fflush(stdin);
  51.         printf("Su año de nacimiento es: ");
  52.         scanf("%d", &p->anonac);
  53.         fflush(stdin);
  54.         printf("Su sexo es: ");
  55.         scanf("%c", &p->sexo);
  56.     }
  57.  
  58. int EdadPanda(mip p)
  59.     {
  60.         int edadp;
  61.         edadp=2018-p.anonac;
  62.         return(edadp);
  63.     }
  64.  
  65. int TenerBebes(mip p)
  66.     {
  67.         int res, edad;
  68.         edad=EdadPanda(p);
  69.         if (edad>=5 && (p.sexo=='f' || p.sexo=='F'))
  70.             res=1;
  71.         else
  72.         {
  73.             res=0;
  74.         }
  75.         return(res);
  76.     }
Advertisement
Add Comment
Please, Sign In to add comment