C Program on Structures

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Program for Structure
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct product
{
    char pname[50];
    int qty;
    int price;
};struct product p[5];
int main()
{
    system("cls");
    int i;
    for(i=0;i<5;i++)
    {
          fflush(0);
          printf("\n Enter Product Name: ");
          scanf("%s",p[i].pname);
          fflush(0);
          printf("\n Enter Product Qty: ");
          scanf("%d",&p[i].qty);
          fflush(0);
          printf("\n Enter Product Price: ");
          scanf("%d",&p[i].price);
    }
    printf("\n-------------------------------------------------");
    printf("\nName \t Qty \t Price \t Amount ");
    printf("\n-------------------------------------------------");
    int total=0;
    for(i=0;i<5;i++)
    {
          printf("\n");
          printf("%s \t %d \t %d \t %d",p[i].pname,p[i].qty,p[i].price,p[i].qty*p[i].price);
           total=total+p[i].qty*p[i].price; 
    }
     printf("\n--------------------------------------------------");
     printf("\n \t \t Total Amount %d ",total);
    return 0;

}

 

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

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