IC Ass4
IC Ass4
VU22CSEN0100127
B.Venkata Satya
1. Write a C program that defines a structure called Student to store the details of a student including
name, roll number, and
marks in three subjects (Physics, Chemistry, and Mathematics). The program should prompt the user
to input the details of
three students, store them in an array of Student structures, and then print the details of all
students.
CODE
#include <stdio.h>
mathematics;
};
of 3 students
&students[i].rollNumber); printf("Marks in
&students[i].chemistry); printf("Marks in
&students[i].mathematics);
}
// Print details of all students printf("\nDetails of
printf("\n");
return 0;
OUTPUT:
2. Write a C program that defines a structure called Book to store the details of books including title,
author, and price. The
program should then create an array of Book structures to store the details of three books. After
storing the details, the program should print the details of all books.
CODE:
#include <stdio.h>
char author[50];
float price;
};
details of 3 books
n]", books[i].title);
n]", books[i].author);
printf("Price: ");
scanf("%f", &books[i].price);
nDetails of Books:\n");
printf("\n");
return 0;
OUTPUT
3. Write a C program that defines a structure called Employee to store the details of an employee
including name, ID, and
salary. The program should then create a pointer to an Employee structure and allocate memory for
it dynamically using
malloc(). After allocating memory, prompt the user to input the details of an employee using the
pointer, and then print the details of the employee
CODE:
#include <stdio.h>
int id;
float salary;
};
Employee structure
allocation failed!\n");
return 1;
>name);
printf("ID: ");
scanf("%d", &emp->id);
printf("Salary: ");
scanf("%f", &emp->salary);
free(emp);
return 0;
}
OUTPUT: