Está en la página 1de 1

# include "stdio.

h"
# include "conio.h"
# include "stdlib.h"
# include "string.h"
# include "iostream.h"
struct n{
char nom[20];
int edad;
struct n *sig;
}*cabc,*qc,*qs,*cabs;
int main (void)
{
char aux[4];
int i,op;
cabc=NULL;
cabs=NULL;
system("cls");
cout<<"\nDIGITE CUANTOS PERSONAS A CAPTURAR ";
gets(aux);
op=atoi(aux);
for(i=1;i<=op;i++)
{
qc=(struct n*)malloc(sizeof(struct n));
system("cls");
cout<<"\nDIGITE EL "<<i<<" NOMBRE ";
gets(qc->nom);
cout<<"\nDIGITE SU EDAD ";
gets(aux);
qc->edad=atoi(aux);
if(cabc==NULL)
qc->sig=qc;
else
{
qc->sig=cabc->sig;
cabc->sig=qc;
}
cabc=qc;
}
system("cls");
if(cabc!=NULL)
{
cout<<"\nEL CONTENIDO DE LA LISTA ES ";
qc=cabc->sig;
do{
if(qc->edad < 18 )
{
qs=(struct n*)malloc(sizeof(struct n));
strcpy(qs->nom,qc->nom);
qs->edad=qc->edad;
qs->sig=cabs;
cabs=qs;
}
cout<<"\nNombre: "<<qc->nom<<" Edad: "<<qc->edad;
qc=qc->sig;
}while(qc!=cabc->sig);
if(cabs != NULL)
{
cout<<"\n\nMENORES DE EDAD \n";
qs=cabs;
do{
cout<<"\nNombre: "<<qs->nom<<" Edad: "<<qs->edad;
qs=qs->sig;
}while(qs != NULL);
}
else
cout<<"\n\nNo existen menores de edad";
}
else
cout<<"\nNO EXISTE LISTA";
getch();
return(0);
}
Los valores a ingresar son los siguientes: -3, 3, juan, 23, ana, 16, pedro, 25

También podría gustarte