Q.1 Write
a C program to declare book structure (bookno, bookname, author). Accept
details of n books and display books of particular author.
#include<stdio.h>
#include<string.h>
struct book
{
char book_name[30];
char author[30];
int book_id;
};
int main()
{
struct book b[100]; // Here b is a variable of structure book
int i,n;
char temp[30];
printf("Welcome to DataFlair tutorials!\n\n");
printf("How many the record of books:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the book name: ");
scanf("%s",b[i].book_name);
printf("Enter the author name: ");
scanf("%s",b[i].author);
printf("Enter the book ID: ");
scanf("%d",&b[i].book_id);
}
printf("\nThe details of the book are:\n\n");
for(i=0;i<n;i++)
{
printf("The book name is: ");
puts(b[i].book_name);
printf("The author name is: ");
puts(b[i].author);
printf("The book ID is: %d\n",b[i].book_id);
}
printf("\nEnter Author Name: ");
scanf("%s",temp);
printf("--------------------------------------");
for(i=0;i<n;i++)
{
if(strcmp(b[i].author,temp)==0)
{
printf("\n%s\n",b[i].book_name);
}
}
return(0);
}
Q.2 Write a C program to declare employee structure (eno, ename, salary). Accept details of n employees and display salary of particular employee.
Q.3 Write a C program to declare student structure (sno, sname, percentage). Accept details of n students and display percentage of particular student.
Comments
Post a Comment