Sunday, 24 April 2022

3. Define a structure called Item with members: Item_code, Item_name, Price. Create an array of five Items. Create a function which accepts the Item array and modifies each element with an increase of 10% in the price.

 



#include<stdio.h>
#include<conio.h>

struct item
{
    long item_code;
    char item_name[20];
    float  price;
}i[5];

void acceptitem();

void main()
{
    clrscr();

    acceptitem();

    getch();
}

void acceptitem()
{
    int no,j;
    float temp;

    printf("\nhow many item: ");
    scanf("%d",&no);

    if(no>5)
    {
        printf("\n\n!! enter less than 5 !!");
    }
    else
    {
        for(j=0; j<no; j++)
        {
            printf("\nenter %d item code: ",j+1);
            scanf("%ld",&i[j].item_code);
            printf("enter %d item name: ",j+1);
            scanf("%s",i[j].item_name);
            printf("enter %d item price: ",j+1);
            scanf("%f",&i[j].price);
            printf("\n");
        }

        printf("\nyour items:\n");
        for(j=0; j<no; j++)
        {
            printf("\n%d item code: %ld",j+1,i[j].item_code);
            printf("\n%d item name: %s",j+1,i[j].item_name);
            temp = i[j].price ;
            i[j].price = i[j].price * 10 / 100;
            i[j].price = temp + i[j].price;
            printf("\n%d item price: %0.2f",j+1,i[j].price);
            printf("\n");
        }
    }
    getch();
}

void dummy()
{
    float x,*y;
    y = &x;
    x = *y;
}

/*      output:

how many item: 2

enter 1 item code: 1234
enter 1 item name: milk
enter 1 item price: 120


enter 2 item code: 1345
enter 2 item name: drink
enter 2 item price: 157


your items:

1 item code: 1234
1 item name: milk
1 item price: 132.00

2 item code: 1345
2 item name: drink
2 item price: 172.70

*/

No comments:

Post a Comment

python programs

1. sum of two number