Advertisement
Guest User

Untitled

a guest
Nov 8th, 2023
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. struct Book {
  4.     char title[100];
  5.     int volume;
  6.     int year;
  7.     char author[100];
  8. };
  9. struct Magazine {
  10.     char title[100];
  11.     int volume;
  12.     int month;
  13.     int year;
  14.     char editorialBoard[100];
  15. };
  16. struct Newspaper {
  17.     char title[100];
  18.     int volume;
  19.     int day;
  20.     int month;
  21.     int year;
  22.     char editor[100];
  23. };
  24. struct Book books[10];
  25. struct Magazine magazines[10];
  26. struct Newspaper newspapers[10];  
  27. int main(){
  28.     int numBooks,numMagazine,numNewspapers,year;
  29.     printf("Enter the number of books: ");
  30.     scanf("%d",&numBooks);
  31.     printf("Enter number of journals: ");
  32.     scanf("%d",&numMagazine);
  33.     printf("Enter number of newspapers: ");
  34.     scanf("%d",&numNewspapers);
  35.     int i;
  36.     for(i=0;i<numBooks;i++){  
  37.         printf("Book %d\n",i+1);
  38.         printf("Title: ");
  39.         scanf("%s",&books[i].title);
  40.         printf("Volume: ");
  41.         scanf("%d",&books[i].volume);
  42.         printf("Year: ");
  43.         scanf("%d",&books[i].year);
  44.         printf("Author: ");
  45.         gets(books[i].author);
  46.     }
  47.     int j;
  48.     for(j=0;j<numMagazine;j++){
  49.         printf("Journal %d\n",j+1);
  50.         printf("Title: ");
  51.         scanf("%s",&magazines[j].title);
  52.         printf("Volume: ");
  53.         scanf("%d",&magazines[j].volume);
  54.         printf("Month: ");
  55.         printf("Year: ");
  56.         scanf("%d",&magazines[j].year);
  57.         scanf("%d",&magazines[j].month);
  58.         printf("Editors: ");
  59.         gets(magazines[j].editorialBoard);
  60.     }
  61.     int k;
  62.     for(k=0;k<numNewspapers;k++){
  63.         printf("Newspaper %d\n",k+1);
  64.         printf("Title: ");
  65.         scanf("%s",&newspapers[k].title);
  66.         printf("Volume: ");
  67.         scanf("%d",&newspapers[k].volume);
  68.         printf("Month: ");
  69.         printf("Year: ");
  70.         printf("Day: ");
  71.         scanf("%d",&newspapers[k].year);
  72.         scanf("%d",&newspapers[k].month);
  73.         scanf("%d",&newspapers[k].day);
  74.         printf("Editors: ");
  75.         gets(newspapers[k].editor);
  76.     }    
  77.     printf("\nEnter the year: ");
  78.     scanf("%d",&year);
  79.     int n;
  80.     for(n=0;n<numBooks;++n){
  81.         if(books[i].year == year)
  82.             printf("Book: %s, Author: %s\n",books[i].title,books[i].author);
  83.     }  
  84.     int l;
  85.     for(l=0;l<numMagazine;++l){
  86.         if(magazines[j].year == year)
  87.             printf("Magazine: %s, Editors: %s\n",magazines[j].title,books[j].editorialBoard);
  88.     }      
  89.     for(int m = 0; m<numNewspapers ; m++){
  90.         if(newspapers[k].year == year){
  91.             printf("Newpaper: %s , Editor: %s \n",newspapers[k].title ,newspapers[k].editor);
  92.         }  
  93.     }      
  94.     return 0;  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement