Lab Assignment 11
Lab Assignment 11
#include<stdio.h>
int main()
{
struct student
{
int rollno;
char name[10];
int marks;
};
return 0;
}
Output:
#include<stdio.h>
int main()
{
struct student
{
int rollno;
char name[10]; int marks;
}stud[3];
int i;
for(i=0;i<=2;i++)
{
printf("enter data for student %d:",i+1);
scanf("%d %s %d",&stud[i].rollno,&stud[i].name,&stud[i].marks);
}
for(i=0;i<=2;i++)
{
printf("data for student %d: ",i+1);
printf("%d %s %d\n",stud[i].rollno,stud[i].name,stud[i].marks);
}
Output:
Q.)Structure as a input of another structure i/o.
#include<stdio.h>
int main()
{
struct marks
{
int phy; int chem; int maths;
};
struct student
{
int rollno;
char name[10];
struct marks m;
}stud[3];
int i,sum=0,sum1=0,sum2=0;
for(i=0;i<=2;i++)
{
printf("enter data for student:");
scanf("%d %s",&stud[i].rollno,stud[i].name);
printf("marks in physics, chemistry and maths");
scanf("%d %d %d",&stud[i].m.phy,&stud[i].m.chem,&stud[i].m.maths);
}
for(i=0;i<=2;i++)
{
printf("\n %d %s %d %d
%d",stud[i].rollno,stud[i].name,stud[i].m.phy,stud[i].m.chem,stud[i].m.maths)
;
}
for(i=0;i<=2;i++)
{
sum=sum+stud[i].m.phy; sum1=sum1+stud[i].m.chem;
sum2=sum2+stud[i].m.maths;
}
Output.
Q1.)
#include <stdio.h>
#include <string.h>
struct student {
char rollno[10];
char name[50];
char department[8];
char course[20];
int year_of_joining;
}std[250];
int main() {
struct student std[250] = {
{"241036001", "T", "CSE", "B.Tech", 2022},
{"241036002", "D", "CSE", "B.Tech", 2024},
{"241034012", "R", "CSE", "B.Tech", 2023},
{"241033030", "P", "CSE", "B.Tech", 2024},
{"241036003", "A", "CSE", "B.Tech", 2021},
{"241033030", "B", "CSE", "B.Tech", 2024},
{"241033037", "G", "CSE", "B.Tech", 2023},
{"241033034", "H", "CSE", "B.Tech", 2023},
{"241033031", "J", "CSE", "B.Tech", 2022},
{"241033033", "K", "CSE", "B.Tech", 2024}
};
int year;
char roll[10];
return 0;
}
Output.
Q2.)
#include <stdio.h>
#include <string.h>
struct customer {
int account_number;
char name[50];
float balance;
};
int main() {
struct customer customers[MAX_CUSTOMERS];
int n, acc_number, code;
float amount;
printf("Name: ");
scanf(" %[^\n]s",customers[i].name);
printf("Balance: ");
scanf("%f", &customers[i].balance);
}
print_low_balance(customers, n);
return 0;
}
Q3.)
#include <stdio.h>
#include <string.h>
struct date {
int day;
int month;
int year;
};
struct employee {
int empcode;
char name[50];
struct date date_of_joining;
};
return years;
}
int main() {
int n;
printf("Enter number of employees: ");
scanf("%d", &n);
printf("Name: ");
scanf(" %[\n]s",employees[i].name);
#include <stdio.h>
#include <string.h>
struct library {
int accession_number;
char title[50];
char author[50];
float price;
int is_issued;
};
int found = 0;
for (int i = 0; i < count; i++) {
if (strcmp(books[i].author, author) == 0) {
printf("Title: %s\n", books[i].title);
found = 1;
}
}
if (!found) {
printf("No books found by author %s.\n", author);
}
}
int found = 0;
for (int i = 0; i < count; i++) {
if (strcmp(books[i].title, title) == 0) {
printf("Accession Number: %d\n", books[i].accession_number);
printf("Author: %s\n", books[i].author);
printf("Price: %.2f\n", books[i].price);
printf("Issued: %s\n", books[i].is_issued ? "Yes" : "No");
found = 1;
}
}
if (!found) {
printf("No book found with title %s.\n", title);
}
}
int main() {
struct library books[MAX_BOOKS];
int count = 0;
int choice;
do {
printf("\nLibrary Menu:\n");
printf("1. Add book information\n");
printf("2. Display book information\n");
printf("3. List all books of a given author\n");
printf("4. List the title of a specified book\n");
printf("5. List the count of books in the library\n");
printf("6. List the books in the order of accession number\n");
printf("7. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_book(books, &count);
break;
case 2:
display_books(books, count);
break;
case 3:
list_books_by_author(books, count);
break;
case 4:
find_book_by_title(books, count);
break;
case 5:
count_books(count);
break;
case 6:
list_books_by_accession_number(books, count);
break;
case 7:
printf("Exiting the program.\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 7);
return 0;
}
Output.