The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Code
By Guest on 25th January 2023 06:18:29 AM | Syntax: TEXT | Views: 13



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct Book
  4. {
  5.         int *ptr;
  6.         char Name[50];
  7.         int Pages;
  8.         float Price;   
  9. }x[100];
  10.  
  11. int main()
  12. {
  13.         int i,n;       
  14.         printf("Enter no. of books: ");
  15.         scanf("%d",&n);
  16.         x[i].ptr=(int*)malloc(n*sizeof(int));
  17. if(x[i].ptr==NULL)
  18. {
  19.         printf("Memory not allocated");
  20. }
  21. else{
  22.         printf("Enter Book details: ");
  23.         for(i=0;i<n;i++)
  24.         {
  25.         printf("\nEnter Name: ");
  26.         scanf("%s",&x[i].Name);
  27.         printf("Enter pages: ");
  28.         scanf("%d",&x[i].Pages);
  29.         printf("Enter Price: ");
  30.         scanf("%f",&x[i].Price);
  31.         }
  32.         for(i=0;i<n;i++)
  33.         {
  34.         printf("\nThe details of book are: "); 
  35.         printf("\nName: %s ",x[i].Name);
  36.         printf("\nPages:%d ",x[i].Pages);
  37.         printf("\nPrice:%f",x[i].Price);
  38.         }
  39. }
  40. }



  • Recent Pastes
  • Questions
    14 hours 26 mins 36 secs ago
  • Adrs
    14 hours 31 mins 46 secs ago
  • Docs
    14 hours 32 mins 30 secs ago
  • Servs
    14 hours 33 mins 13 secs ago
  • Srvs
    14 hours 38 mins 2 secs ago