6
C Programming - Structures Organized By: Vinay Arora Assistant Professor, CSED Thapar University, Patiala

C Prog. - Structures

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: C Prog. - Structures

C Programming - Structures

Organized By: Vinay Arora

Assistant Professor, CSED

Thapar University, Patiala

Page 2: C Prog. - Structures

Vinay Arora

CSED

Program - 1

#include<stdio.h>

#include<conio.h>

void main()

{

char name[3];

float price[3],i;

clrscr();

printf("Enter names, price of 3 books\n");

for(i=0;i<=2;i++)

scanf("\n%c %f",&name[i],&price[i]);

printf("\nAnd this is what you have entered\n");

for(i=0;i<=2;i++)

printf("%c %f\n",name[i],price[i]);

getch();

}

Page 3: C Prog. - Structures

Vinay Arora

CSED

Program – 1 (output)

Page 4: C Prog. - Structures

Vinay Arora

CSED

Program - 2

#include<stdio.h>

#include<conio.h>

void main()

{

struct book

{

char name;

float price;

};

struct book b1,b2,b3;

clrscr();

printf("Enter names, price of 3 books\n");

scanf("\n%c %f",&b1.name,&b1.price);

scanf("\n%c %f",&b2.name,&b2.price);

scanf("\n%c %f",&b3.name,&b3.price);

printf("\nAnd this is what you have entered\n");

printf("\n%c %f",b1.name,b1.price);

printf("\n%c %f",b2.name,b2.price);

printf("\n%c %f",b3.name,b3.price);

getch();

}

Page 5: C Prog. - Structures

Vinay Arora

CSED

Program – 2 (output)

Page 6: C Prog. - Structures

Vinay Arora

CSED

Thnx…