Thursday, August 19, 2010

C Programming - read value using scanf () and assign them to structure variables

#include<stdio.h>
#include<conio.h>
main()
{
struct book1
{
char book[30];
int pages;
float price;
};
struct book1 b;
clrscr();
printf("\n enter book name,pages,price:");
scanf("\n %s",b.book);
scanf("\n %d",&b.pages);
scanf("\n %f",&b.price);
printf("\n bookname:%s",b.book);
printf("\n no of pages:%d",b.pages);
printf("\n book price:%f",b.price);
getch();
}

output:-enter book name,pages,price:c
500
450
book name:c
no. of pages:500
price:450

No comments:

Post a Comment