C Program to Print Bill Details using Array of Structure

C Program to Print Bill 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 billno,amt;
    char date[10];
}s[3];

main()
{
    int i;
    void line(void);
    for(i=1;i<=3;i++)
    {
        line();
        printf("\nEnter Bill %d Details..\n",i);
        line();
        printf("\nEnter Bill Number\n");
        scanf("%d",&s[i].billno);
        printf("Enter Date (D/M/Y)\n");
        scanf("%s",s[i].date);
        printf("Enter Amount\n");
        scanf("%d",&s[i].amt);
        printf("\n");
    }
    printf("\nBill details...\n\n");
    line();
    printf("\n");
    printf("Bill_No\tDate\tAmount\n");
    line();
    printf("\n");
    for(i=1;i<=3;i++)
    {
        printf("%d\t\t%s\t\t%d\n",s[i].billno,s[i].date,s[i].amt);
    }
    line();

    printf("\n\n");
    printf("Displaying records having amount > 1000\n");
    line();
    printf("\n");
    printf("Bill_No\tDate\tAmount\n");
    for(i=1;i<=3;i++)
    {
        if(s[i].amt>1000)
        {
            line();
            printf("\n");
            printf("%d\t\t%s\t\t%d\n",s[i].billno,s[i].date,s[i].amt);
        }
    }
}
void line()
{
    int i;
    for(i=1;i<100;i++)
        printf("_");
}

OUTPUT:

___________________________________________________________________________________________________
Enter Bill 1 Details..
___________________________________________________________________________________________________
Enter Bill Number
1
Enter Date (D/M/Y)
22/12/16
Enter Amount
50000

___________________________________________________________________________________________________
Enter Bill 2 Details..
___________________________________________________________________________________________________
Enter Bill Number
2
Enter Date (D/M/Y)
14/2/17
Enter Amount
7000

___________________________________________________________________________________________________
Enter Bill 3 Details..
___________________________________________________________________________________________________
Enter Bill Number
3
Enter Date (D/M/Y)
17/12/16
Enter Amount
10000


Bill details...

___________________________________________________________________________________________________
Bill_No Date    Amount
___________________________________________________________________________________________________
1               22/12/16                50000
2               14/2/17                 7000
3               17/12/16                10000
___________________________________________________________________________________________________

Displaying records having amount > 1000
___________________________________________________________________________________________________
Bill_No Date    Amount
___________________________________________________________________________________________________
1               22/12/16                50000
___________________________________________________________________________________________________
2               14/2/17                 7000
___________________________________________________________________________________________________
3               17/12/16                10000

Leave a Reply

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

six − 2 =