Advertisement
Ishmam_Rahman

BestSellerBook

May 22nd, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <stdlib.h>
  3. struct Bfair    {
  4.     char BookName[100];
  5.     char AuthorName[100];
  6.     int CopiesSold;
  7. };
  8.  
  9. void BestSeller(struct Bfair arr[],int n) {
  10.     FILE *fp;
  11.     fp = fopen("bestbook.txt", "w");
  12.  
  13.     int mx=0,i;
  14.     for(i=0;i<n;i++) {
  15.         if(arr[i].CopiesSold>mx) mx=arr[i].CopiesSold;
  16.     }
  17.  
  18.     for(i=0;i<n;i++) {
  19.         if(arr[i].CopiesSold==mx){
  20.             fprintf(fp,"BookName: ");
  21.             fprintf(fp,"%s\n",arr[i].BookName);
  22.  
  23.             fprintf(fp,"AuthorName: ");
  24.             fprintf(fp,"%s\n",arr[i].AuthorName);
  25.  
  26.             fprintf(fp,"CopiesSold: %d\n\n",arr[i].CopiesSold);
  27.         }
  28.     }
  29. }
  30.  
  31.  
  32. int main() {
  33.  
  34.     struct Bfair vr[200];
  35.     int i=0;
  36.  
  37.     for(i=0;i<200;i++) {
  38.         printf("Enter the Book name: ");
  39.         gets(vr[i].BookName);
  40.         printf("Enter the Book's Author name: ");
  41.         gets(vr[i].AuthorName);
  42.         printf("Enter the Book's sold copy number: ");
  43.         scanf("%d",&vr[i].CopiesSold);
  44.         getchar();
  45.     }
  46.  
  47.     BestSeller(vr,200);
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement