C Program to Store and Display Records of N Products Using Structure (स्ट्रक्चर का उपयोग करके N प्रोडक्ट्स के रिकार्ड्स स्टोर और डिस्प्ले करना)

In C language, an array of structures is used to store and display records of multiple products. Each product record contains product ID, product name, manufacturing date, supplier name and price.

C Language में Multiple Products के Records को Store और Display करने के लिए Array of Structures का उपयोग किया जाता है। प्रत्येक Product के Record में Product ID, Product Name, Manufacturing Date, Supplier Name और Price शामिल होते हैं।

C Program

#include <stdio.h>
#include <string.h>
#define N 10
struct product
{
int pid;
char pname[20];
char mfd[11];
char sname[20];
float price;
};
int main()
{
int i;
struct product p[N];
// Input product records
for (i = 0; i < N; i++)
{
printf("\nEnter details of Product %d:\n", i + 1);
printf("Enter product ID: ");
scanf("%d", &p[i].pid);
getchar();
printf("Enter product name: ");
fgets(p[i].pname, sizeof(p[i].pname), stdin);
p[i].pname[strcspn(p[i].pname, "\n")] = '\0';
printf("Enter manufacturing date (DD/MM/YYYY): ");
fgets(p[i].mfd, sizeof(p[i].mfd), stdin);
p[i].mfd[strcspn(p[i].mfd, "\n")] = '\0';
printf("Enter supplier name: ");
fgets(p[i].sname, sizeof(p[i].sname), stdin);
p[i].sname[strcspn(p[i].sname, "\n")] = '\0';
printf("Enter price: ");
scanf("%f", &p[i].price);
}
// Display product records
printf("\n========== PRODUCT RECORDS ==========\n");
for (i = 0; i < N; i++)
{
printf("\nDetails of Product %d:\n", i + 1);
printf("Product ID : %d\n", p[i].pid);
printf("Product Name : %s\n", p[i].pname);
printf("Manufacturing Date : %s\n", p[i].mfd);
printf("Supplier Name : %s\n", p[i].sname);
printf("Price : Rs. %.2f\n", p[i].price);
}
return 0;
}

Sample Output

Enter details of Product 1:
Enter product ID: 101
Enter product name: Laptop
Enter manufacturing date (DD/MM/YYYY): 15/08/2026
Enter supplier name: ABC Traders
Enter price: 45000

========== PRODUCT RECORDS ==========
Details of Product 1:
Product ID : 101
Product Name : Laptop
Manufacturing Date : 15/08/2026
Supplier Name : ABC Traders
Price : Rs. 45000.00
... Records of remaining products ...

Note: The program accepts and displays records of all 10 products.

Explanation

  1. Structure Declaration: struct product defines five members to store product details.

    struct product में Product की जानकारी Store करने के लिए पाँच Members Declare किए गए हैं।

  2. Array of Structures: struct product p[N]; creates an array to store 10 product records.

    यह Statement 10 Products के Records Store करने के लिए Array बनाता है।

  3. Input: The first for loop accepts product details from the user.

    पहला for Loop यूजर से सभी Products की जानकारी Input करता है।

  4. Display: The second for loop displays all stored product records.

    दूसरा for Loop Store किए गए सभी Product Records को Display करता है।

  5. Member Access: The dot (.) operator accesses individual structure members.

    Dot (.) Operator की सहायता से Structure के अलग-अलग Members को Access किया जाता है।

Important Points

  • #define N 10 specifies the number of products.

  • An array of structures stores multiple product records.

  • Manufacturing date is stored as a character array.

  • fgets() accepts product names and supplier names containing spaces.

  • The price is stored using the float data type.

महत्वपूर्ण बिंदु:

  • #define N 10 Products की संख्या निर्धारित करता है।

  • Array of Structures का उपयोग Multiple Product Records Store करने के लिए किया जाता है।

  • Manufacturing Date को Character Array में Store किया जाता है।

  • fgets() की सहायता से Space सहित Product और Supplier के नाम Input किए जा सकते हैं।

  • Price को float Data Type में Store किया जाता है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025