Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct
- {
- int nr_pag:4;
- char domeniu[15];
- char editura[15];
- }revista;
- typedef struct
- {
- int an:4;
- char titlu[15];
- char autor[15];
- }carte;
- typedef union
- {
- revista r;
- carte c;
- }prob;
- typedef struct
- {
- int nr_exemplare:4;
- prob publ;
- }pub[15];
- int main()
- {
- int n,k=0;
- char tip;
- printf("Dati numarul de publicatii: ");
- scanf("%d",&n);
- while(n)
- {
- printf("Dati tipul publicatiei(r-revista|c-carte): ");
- scanf("%c",&tip);
- if(tip=='r')
- {
- printf("Numarul de exemplare: ");
- scanf("%d",pub[k].nr_exemplare);
- printf("Domeniul: ");
- scanf("%s",pub[k].publ.r.domeniu);
- printf("Editura: ");
- scanf("%s",pub[k].publ.r.editura);
- printf("Nr. pag.: ");
- scanf("%d",pub[k].publ.r.nr_pag);
- k++;
- }
- if(tip=='c')
- {
- printf("Numarul de exemplare: ");
- scanf("%d",pub[k].nr_exemplare);
- printf("An: ");
- scanf("%s",pub[k].publ.c.an);
- printf("Autor: ");
- scanf("%s",pub[k].publ.c.autor);
- printf("Titlu: ");
- scanf("%d",pub[k].publ.c.titlu);
- k++;
- }
- if(tip!='c' && tip!='r')
- n++;
- n--;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement