Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct lista
- {
- int val;
- struct lista *urm;
- };
- typedef struct lista LISTA;
- int main(void)
- {
- LISTA *primul, *p, *q, *aux;
- int i, nr;
- printf("Introduceti numarul de elemnte: ");
- scanf("%d", &nr);
- p=(LISTA*)malloc(sizeof(LISTA));
- if ( p == NULL)
- {
- printf("Alocare dinamica esuata!");
- exit(1);
- }
- printf("Tastati valoarea primului element: ");
- scanf("%d", &p->val);
- p->urm = NULL;
- primul = p;
- for (i=1; i<nr; i++)
- {
- q = (LISTA*)malloc(sizeof(LISTA));
- if (q == NULL)
- {
- printf("Alocare dinamica esuata!");
- exit(1);
- }
- printf("Tastati valoare elementului %d: ", i+1);
- scanf("%d", &q->val);
- q->urm = NULL;
- p->urm = q;
- p = q;
- }
- for(p=primul, i=0; p != NULL; p = p->urm, i++)
- //if (p->val % 2 == 0)
- aux = primul;
- if (p->val) % 2 == 0)
- {
- primul = aux->urm;
- free(aux);
- }
- for(p=primul, i=0; p != NULL; p = p->urm, i++)
- printf("%d", p->val);
- for (p=primul; p != NULL; p=q)
- {
- q = p->urm;
- free(p);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement