20120113

How to use Structures in C

//========================
//Program in Cto learn structures in C, struct4.c
//========================
// array of structures, collection of collection of hetrogeneous data types

#include<stdio.h>
int main()
{
struct book
        {
        char name;
        int pages;
        float price;
        };
        struct book b[5]; // b is array of 5 books
        int i;
        for(i=0;i<5;i++)

                {
                printf("\n Enter the name,pages and price of book %d",i);
                scanf("%c %d %f",&b[i].name,&b[i].pages,&b[i].price);
                }
        for(i=0;i<5;i++)
                {
                printf("\n %c %d %f",b[i].name,b[i].pages,b[i].price);
                }
//return 0;
}
Previous                             Home                               Next

No comments:

Post a Comment