Q:

Write a C program to demonstrate example of structure pointer

0

Write a C program to demonstrate example of structure pointer

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
 
struct item
{
    char itemName[30];
    int qty;
    float price;
    float amount;
};
 
int main()
{
 
    struct item itm;
    struct item *pItem;
 
    pItem = &itm;
 
    // reading values using pointer
    printf("Enter product name: ");
    gets(pItem->itemName);
    printf("Enter price:");
    scanf("%f",&pItem->price);
    printf("Enter quantity: ");
    scanf("%d",&pItem->qty);
 
    //calculating total amount of all quantity
    pItem->amount =(float)pItem->qty * pItem->price;
 
    //printing item details
    printf("\nProduct Name: %s",pItem->itemName);
    printf("\nProduct Price: %f",pItem->price);
    printf("\nProduct Quantity: %d",pItem->qty);
    printf("\nTotal Amount: %f",pItem->amount);
 
    return 0;
}

Result:

Enter product name: Pencil

Enter price:15

Enter quantity: 25

Product Name: Pencil

Product Price: 15.000000

Product Quantity: 25

Total Amount: 375.000000

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a C program to calculate percentage of stude... >>
<< Write a C Program to add two distances in inch-fee...