C Program to Display Item Details using Array of Structure

C Program to Display Item Details using Array of Structure:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
struct item
{
    int itcode,qty;
    char desc[10];
}s[3];
main()
{
    int i,max=0,j=0;;
    void line(void);
    line();
    for(i=0;i<3;i++)
    {
        printf("Enter %d details\n",i+1);
        line();
        printf("Enter item no\n");
        scanf("%d",&s[i].itcode);
        printf("Enter description\n");
        scanf("%s",s[i].desc);
        printf("Enter quantity\n");
        scanf("%d",&s[i].qty);
        line();
    }

    printf("Item details are...\n");
    line();
    printf("Itcode\tDescription\tQuantity\n");
    line();
    for(i=0;i<3;i++)
    {
        printf("%d\t%s\t%d\n",s[i].itcode,s[i].desc,s[i].qty);
    }
    line();

    printf("Items having highest quantity\n");
    max=s[0].qty;
    line();
    for(i=1;i<3;i++)
    {
        if(s[i].qty>max)
        {
            max=s[i].qty;
            j=i;
        }
    }
    printf("%d\t%s\t%d\n",s[j].itcode,s[j].desc,s[j].qty);
}
void line()
{
    int i;
    for(i=0;i<100;i++)
    {
        printf("_");
    }
    printf("\n");
}

OUTPUT:

____________________________________________________________________________________________________
Enter 1 details
____________________________________________________________________________________________________
Enter item no
1
Enter description
Pen
Enter quantity
80
____________________________________________________________________________________________________
Enter 2 details
____________________________________________________________________________________________________
Enter item no
2
Enter description
Pencil
Enter quantity
100
____________________________________________________________________________________________________
Enter 3 details
____________________________________________________________________________________________________
Enter item no
3
Enter description
Scale
Enter quantity
120
____________________________________________________________________________________________________
Item details are...
____________________________________________________________________________________________________
Itcode  Description     Quantity
____________________________________________________________________________________________________
1       Pen     80
2       Pencil  100
3       Scale   120
____________________________________________________________________________________________________
Items having highest quantity
____________________________________________________________________________________________________
3       Scale   120

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.