Advertisement
Guest User

Untitled

a guest
May 24th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <cstring>
  5.  
  6. struct book
  7. {
  8. char name[30];
  9. char field[30];
  10. int year;
  11. };
  12.  
  13.  
  14.  
  15.  
  16.  
  17. int main() {
  18. book libry[3];
  19. int i, k;
  20. for (i = 0; i < 3; i++)
  21. {
  22. printf("Enter name of %d book:", i + 1);
  23. gets_s(libry[i].name);
  24. printf("Enter field of %d book:", i + 1);
  25. gets_s(libry[i].field);
  26. printf("Enter year of %d book:", i + 1);
  27. scanf("%d", &libry[i].year);
  28. getchar();
  29. }
  30. for (i = 0; i < 3; i++)
  31. {
  32. printf("\n %d. %s", i + 1, libry[i].name);
  33. printf(", %s , %d", libry[i].field, libry[i].year);
  34. }
  35.  
  36. k = 0;
  37. for (int i = 0; i < 3; i++)
  38. if (strcmp(libry[i].field, "Physics") == 0)
  39. k = k + 1;
  40. printf("\n Sum of Physics books: %d", k);
  41.  
  42.  
  43. int oldest_number = 0;
  44. for (int i = 1; i < 3; i++) {
  45. if (libry[oldest_number].year > libry[i].year){
  46. oldest_number = i;
  47. }
  48. }
  49. printf("\n Oldest is: %s with year %d", libry[oldest_number].name, libry[oldest_number].year);
  50.  
  51.  
  52.  
  53. getchar();
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement