0% found this document useful (0 votes)
3 views

Assignment 11

Uploaded by

Chirag Duhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment 11

Uploaded by

Chirag Duhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ASSIGNMENT-11

Q1. Write a program to store 10 books issued and available in a library. Store Book name, Book
reference number, student issued roll number, department.

Ans. #include<string.h>

struct library{

char Book[10];

int ref;

int Roll;

char dept[10];

}lib[10];

int main(){

for(int i=0;i<10;i++){

printf("Enter the details Book %d:",i+1);

scanf("%s%d%d%s",&lib[i].Book,&lib[i].Ref,&lib[i].Roll,&lib[i].dept);

printf("\n");

printf("The book details are :\n");

for(int j=0;j<10;j++){

printf("%s\t\t%d\t\t%d\t\t%s\n",lib[j].Book,lib[j].Ref,lib[j].Roll,lib[j].dept);

return 0;

Output:

Enter the details Book 1:maths

1122

23109006
me

Enter the details Book 2:physics

2233

23109005

me

Enter the details Book 3:chemistry

3344

23103003

che

Enter the details Book 4:computer

4455

23101008

cse

Enter the details Book 5:electrical

5566

23104090

ece

Enter the details Book 6:thermodynamics

6677

23109008

me

Enter the details Book 7:history

7788

23106009

ice

Enter the details Book 8:political

8899

23104008

che
Enter the details Book 9:geography

9999

23102002

ce

Enter the details Book 10:environment

1000

23109080

me

The book details are :

maths 1122 23109006 me

physics 2233 23109005 me

chemistry 3344 23103003 che

computer 4455 23101008 cse

electrical 5566 23104090 ece

thermodynamics 6677 23109008 me

history 7788 23106009 ice

political 8899 23104008 che

geography 9999 23102002 ce

environment 1000 23109080 me

Q2. Write a program to calculate the difference between two time periods using structures.

Ans.

#include <stdio.h>

struct Time {

int hours;

int minutes;

int seconds;

};
struct Time calculateTimeDifference(struct Time t1, struct Time t2) {

struct Time diff;

int t1Seconds = t1.hours * 3600 + t1.minutes * 60 + t1.seconds;

int t2Seconds = t2.hours * 3600 + t2.minutes * 60 + t2.seconds;

int totalSeconds = t1Seconds > t2Seconds ? t1Seconds - t2Seconds : t2Seconds - t1Seconds;

diff.hours = totalSeconds / 3600;

totalSeconds %= 3600;

diff.minutes = totalSeconds / 60;

diff.seconds = totalSeconds % 60;

return diff;

int main() {

struct Time startTime, endTime, timeDiff;

printf("Enter start time (hh:mm:ss): ");

scanf("%d%d%d", &startTime.hours, &startTime.minutes, &startTime.seconds);

printf("Enter end time (hh:mm:ss): ");

scanf("%d%d%d", &endTime.hours, &endTime.minutes, &endTime.seconds);

timeDiff = calculateTimeDifference(endTime, startTime);

printf("Time difference: %02d:%02d:%02d\n", timeDiff.hours, timeDiff.minutes, timeDiff.seconds);


return 0;

Output:

Enter start time (hh:mm:ss): 02

10

40

Enter end time (hh:mm:ss): 05

20

50

Time difference: 03:10:10

Q3. Write a program to make a simple linked list which stores the marks of students.

Ans.

#include <stdio.h>

#include <stdlib.h>

struct Student {

float marks;

struct Student* next;

};

int main() {

struct Student* head = NULL;

struct Student* student1 = (struct Student*)malloc(sizeof(struct Student));

student1->marks = 80.60;

student1->next = NULL;

head = student1;
printf("Student 1 marks: %.2f\n", head->marks);

free(student1);

return 0;

Output:

Student 1 marks: 80.60

You might also like