C Programs
C Programs
EX.NO: 8.1
DATE:
QUESTION:
Declare a book with <title, float price, int number_of_pages>. Read the details of a book
and print the same.
AIM:
To declare a structure called book with <title, float price, int number of pages> , read the
details and print the same.
PSEUDO CODE:
#include <stdio.h>
struct Book
{
char title[100];
float price;
int number_of_pages;
};
int main()
{
struct Book b;
printf("Enter title, price, and number of pages:\n");
scanf("%s %f %d", b.title, &b.price, &b.number_of_pages);
printf("Title: %s\nPrice: %.2f\nPages: %d", b.title, b.price, b.number_of_pages);
return 0;
}
SAMPLE OUTPUT:
RESULT:
The C program contains the structure book, reads the details of the book and displays the
details successfully.
EX.NO: 8.2
DATE:
QUESTION:
Read 2 book details and print the details of the costlier book.
AIM:
To read the details of 2 books and print the details of the book which is costlier than the
other.
PSEUDO CODE:
SAMPLE OUTPUT :
RESULT:
The C program reads the details of the two books and prints the details of the book which is
costlier successful
EX.NO: 8.3
DATE:
QUESTION:
Create a structure STUDENT with <Roll_no,Name,Gender,marks[5], grades[5],GPA>.
Calculate the grade of each subject (assuming one-to one mapping of marks and grades)
and GPA as the average of marks scored by a student.
AIM:
To create a structure called STUDENT with <Roll_no,Name,Gender,marks[5],
grades[5],GPA> and calculating the grade with GPA being the average marks scored by the
student.
PSEUDO CODE:
#include <stdio.h>
struct STUDENT
{
int Roll_no;
char Name[50];
char Gender;
int marks[5];
char grades[5];
float GPA;
};
int main()
{
struct STUDENT s;
int total = 0;
printf("Enter Roll Number: ");
scanf("%d", &s.Roll_no);
printf("Enter Name: ");
scanf("%s", s.Name);
printf("Enter Gender (M/F): ");
scanf(" %c", &s.Gender);
for (int i = 0; i < 5; i++)
{
printf("Enter marks for subject %d: ", i + 1);
scanf("%d", &s.marks[i]);
s.grades[i] = calculateGrade(s.marks[i]);
total += s.marks[i];
}
SAMPLE OUTPUT:
RESULT:
The C program reads the details of the student, calculates the grade with GPA being the
average marks scored by the student and displays the information successfully.