384 Programming and Data Structures
printf ("n C ar No. Starting Time Reaching Time :nrt");
printf C'thhm m:ssthhm m :ss n”);
fo r (k=0;k<3;k++)
I
scanf (" % d " ,& rl[k].cam o);
scanf ( “% d % d %d",&rl[k].st.hour,&rl[k].st.minute,& rl[k].st.second);
scanf ("% d %d %d",&rl[k].rt.hour,&rl[k].rt.minute,&rl[k].rt.second);
I
printf ( “ ntCarNo. tStartingTime tReaching1im en");
fo r (k=0;k<3;k++)
I
printf ( “ n t% d t" ,rl[k].cam o );
printf ( ut%d:% d:% dtt",rl[k].st.hour,rl[k].st.minute,rl[k].st.second);
p>~*utf ("t%d:%d:%d",rl[k].rt.hour,rl[k].rt.minute,rilkl.rt.second);
I
OUTPUT:
Car No. Starting lim e Reaching Time :
hh:mm:ss hh:mm:ss
120 2 20 25 3 25 58
121
3 25 40
4 40 25
122
4 30 52
5 4010
Car No. Starting Time Reaching Time:
120 2:20:25 3:25:58
121 3:25:40 4:40:25
122 4:30:52 5:40:10
Explanation In the above program two structures time and t are declared. An array of three-
elementsrl [3] isdefined. T h e fir s t fo r loop executes three times and the scan f () statement
reads data through the keyboard for each element of the object. The second f o r loop and the
p r i n t f () statements within it displays the contents of the array of object with their elements.
12.8 Write a program to display names, rollnos, and grades of 3 students who have appeared
in the examination. Declare the structure of name, rollnos and grade. Create an array
of structure objects. Read and display the contents of the array.
# include <stdio.h >
# include <conio.h>
void mainO
{
int k*0;
struct stud