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

