IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY
EX.NO: 8.1
DATE:
PROGRAMS TO ILLUSTRATE STRUCTURES
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:
REGISTER NO : 2127240801093 Page No :
SOURCE 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.
REGISTER NO : 2127240801093 Page No :
IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY
EX.NO: 8.2
DATE:
PROGRAMS TO ILLUSTRATE STRUCTURES
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:
REGISTER NO : 2127240801093 Page No :
SOURCE CODE:
#include <stdio.h>
struct Book
{
char title[100];
float price;
int number_of_pages;
};
int main()
{
struct Book b1, b2;
scanf("%s %f %d", b1.title, &b1.price, &b1.number_of_pages);
scanf("%s %f %d", b2.title, &b2.price, &b2.number_of_pages);
if (b1.price > b2.price)
printf("%s %.2f %d", b1.title, b1.price, b1.number_of_pages);
else
printf("%s %.2f %d", b2.title, b2.price, b2.number_of_pages);
return 0;
}
SAMPLE OUTPUT :
RESULT:
The C program reads the details of the two books and prints the details of the book which is
costlier successful
REGISTER NO : 2127240801093 Page No :
IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY
EX.NO: 8.3
DATE:
PROGRAMS TO ILLUSTRATE STRUCTURES
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:
REGISTER NO : 2127240801093 Page No :
SOURCE CODE:
#include <stdio.h>
struct STUDENT
{
int Roll_no;
char Name[50];
char Gender;
int marks[5];
char grades[5];
float GPA;
};
char calculateGrade(int mark) {
if (mark >= 90) return 'A';
else if (mark >= 80) return 'B';
else if (mark >= 70) return 'C';
else if (mark >= 60) return 'D';
else return 'F';
}
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];
}
REGISTER NO : 2127240801093 Page No :
s.GPA = total / 5.0;
printf("\nStudent Details:\n");
printf("Roll Number: %d\n", s.Roll_no);
printf("Name: %s\n", s.Name);
printf("Gender: %c\n", s.Gender);
for (int i = 0; i < 5; i++) {
printf("Subject %d - Marks: %d, Grade: %c\n", i + 1, s.marks[i], s.grades[i]);
}
printf("GPA: %.2f\n", s.GPA);
return 0;
}
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.
REGISTER NO : 2127240801093 Page No :