Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Grade: AA / AB / BB / BC / CC / CD /DD
TITLE: To store and print the information for Time using structure.
AIM:
Define a structure to store the following information for Time PEriod
● Hours
● Minutes
● Seconds
Accept and store the information for 2 time period. Write a C program to add these 2
time periods, also display the difference between these 2 time periods.
Problem Definition:
Define a structure to store the following information for Time PEriod
● Hours
● Minutes
● Seconds
Accept and store the information for 2 time period. Write a C program to add these 2
time periods, also display the difference between these 2 time periods.
Algorithm:
1. Start.
5. Usinglogic add and subtract time periods aand store them in different n distinct
instances.
6.After addition make sure the values of minutes and seconds are under 60 if not
using logic make proper changes.
9.Stop.
Implementation details:
#include<stdio.h>
#include<stdlib.h>
struct time
{
while(t3.sec>60)
{
t3.sec=t3.sec-60; t3.min=t3.min+1;
}
Department of Science and Humanities
Output(s):
Conclusion:
The program has successfully provide the output of sum of two timeperiods and
difference of two timeperiods.
BASIS OF
COMPARISON STRUCTURE UNION
Store Value Stores distinct values for all Stores same value for
the members. all the members.
BASIS OF
COMPARISON STRUCTURE UNION
Bit fields
In C, we can specify size (in bits) of structure and union members. The idea is to
use memory efficiently when we know that the value of a field or group of fields
will never exceed a limit or is withing a small range
unsigned int y;
};
int main()
{
printf("Size of date is %lu bytes\n", sizeof(struct date)); struct date dt = { 31, 12, 2014 };
printf("Date is %d/%d/%d", dt.d, dt.m, dt.y); return 0;
}
The above representation of ‘date’ takes 12 bytes on a compiler where an
unsigned int takes 4 bytes. Since we know that the value of d is always from 1 to
31, the value of m is from 1 to 12, we can optimize the space using bit fields.
struct founder
{
char ceo[10];
}p;
};
struct org x = {4000, "Ford", "Henry"};
printf("%s %d %s", x.comp, x.employees, x.p.ceo); return 0;
}
ANS:
Date:02/12/2019
Signature of faculty in-charge