Assignment-1 A2
Assignment-1 A2
Q1
#include <stdio.h>
struct Employee {
int id;
char name[50];
char designation[50];
char department[50];
float salary;
};
int main() {
scanf("%d", &emp.id);
scanf("%f", &emp.salary);
printf("\nEmployee Details:\n");
return 0;
Q2
#include <stdio.h>
struct Customer {
int account_no;
char name[50];
float balance;
};
int main() {
scanf("%d", &customers[i].account_no);
printf("Name: ");
printf("Balance: ");
scanf("%f", &customers[i].balance);
print_low_balance(customers, 3);
return 0;
Q3
#include <stdio.h>
#include <string.h>
struct Book {
char title[50];
char author[50];
float cost;
};
int count = 0;
void add_book() {
scanf("%f", &library[count].cost);
count++;
void display_books() {
printf("\nLibrary Books:\n");
if (strcmp(library[i].author, author) == 0) {
int main() {
int choice;
char author[50];
do {
printf("\nLibrary Menu:\n");
scanf("%d", &choice);
switch (choice) {
case 3:
books_by_author(author);
break;
return 0;
Q4
#include <stdio.h>
#include <string.h>
struct Book {
int accession_number;
char title[50];
char author[50];
char publisher[50];
float cost;
};
void display_by_author(struct Book books[], int n, char author[]) {
if (strcmp(books[i].author, author) == 0) {
if (strcmp(books[i].publisher, publisher) == 0) {
printf("\nAll Books:\n");
printf("Accession Number: %d, Title: %s, Author: %s, Publisher: %s, Cost: %.2f\n",
int main() {
int n;
scanf("%d", &n);
books[i].accession_number = i + 1;
printf("Title: ");
printf("Author: ");
printf("Publisher: ");
printf("Cost: ");
scanf("%f", &books[i].cost);
display_by_author(books, n, author);
display_by_publisher(books, n, publisher);
display_costly_books(books, n);
display_all_books(books, n);
return 0;
Q5
#include <stdio.h>
#include <string.h>
struct Employee {
int empid;
char name[50];
float salary;
};
if (employees[i].empid == id) {
return;
printf("\nAll Employees:\n");
int main() {
scanf("%d", &n);
scanf("%d", &employees[i].empid);
printf("Name: ");
printf("Salary: ");
scanf("%f", &employees[i].salary);
do {
printf("\nMenu:\n");
printf("1. Search by Emp-ID\n2. Display All Employees\n3. Display Employees with Salary > 10000\n4.
Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter Employee ID to search: ");
scanf("%d", &id);
search_by_id(employees, n, id);
break;
case 2:
display_all(employees, n);
break;
case 3:
display_high_salary(employees, n);
break;
case 4:
printf("Exiting...\n");
break;
default:
printf("Invalid choice!\n");
return 0;
Q6
#include <stdio.h>
#include <string.h>
union Data {
int number;
char name[20];
};
int main() {
Q7
#include <stdio.h>
union ByteExtractor {
};
int main() {
scanf("%u", &extractor.number);
return 0;
Q8
#include <stdio.h>
union EndiannessCheck {
};
int main() {
check.number = 1;
if (check.byte == 1) {
printf("The machine is Little Endian.\n");
} else {
return 0;