structure for books using arrays
/* there is an issue in the program...while trying to enter the name of the book 2nd time, just after entering price of 1st book...it is jumping to next data*/
#include <stdio.h>
void main()
{ int i;
struct book
{
int nop;
char name;
float price;
}b[2];
for(i=0;i<2;i++)
{
printf("\n enter name of book %d :",i+1);
scanf("%c",&b[i].name);
printf("\n enter no of pages of book %d :",i+1);
scanf("%d",&b[i].nop);
printf("\n enter PRICE of book %d :",i+1);
scanf("%f",&b[i].price);
printf("-------------");
}
for(i=0;i<2;i++)
{
printf("\n name of the book:%c",b[i].name);
printf("\n no of pages:%d",b[i].nop);
printf("\n price:%f",b[i].price);
}
}
{ int i;
struct book
{
int nop;
char name;
float price;
}b[2];
for(i=0;i<2;i++)
{
printf("\n enter name of book %d :",i+1);
scanf("%c",&b[i].name);
printf("\n enter no of pages of book %d :",i+1);
scanf("%d",&b[i].nop);
printf("\n enter PRICE of book %d :",i+1);
scanf("%f",&b[i].price);
printf("-------------");
}
for(i=0;i<2;i++)
{
printf("\n name of the book:%c",b[i].name);
printf("\n no of pages:%d",b[i].nop);
printf("\n price:%f",b[i].price);
}
}
తెరమీద
/tmp/kMZkH5pbco.o
enter name of book 1 :z
enter no of pages of book 1 :205
enter PRICE of book 1 :30.75
-------------
enter name of book 2 :
enter no of pages of book 2 :308
enter PRICE of book 2 :25.25
-------------
name of the book:z
no of pages:205
price:30.750000
name of the book:
no of pages:308
price:25.250000
enter name of book 1 :z
enter no of pages of book 1 :205
enter PRICE of book 1 :30.75
-------------
enter name of book 2 :
enter no of pages of book 2 :308
enter PRICE of book 2 :25.25
-------------
name of the book:z
no of pages:205
price:30.750000
name of the book:
no of pages:308
price:25.250000
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.