6. ......CCaalleennddaarr
main( )
{
i n t d a y s [ ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, … } ;
/* print month year */
/* print days */
for ( i = 1 ; i = days[ m - 1 ] ; i++ )
{
gotorc ( r o w , c o l ) ;
printf ( ”%d”, i ) ;
col = col + 6 ;
if ( col 56 )
{
row++ ; col = 20 ;
} } }
10
20 26 32
Mon - - -Tue - - -Wed---
row = 12 ;
7. main( )
{ . .
scanf ( ”%d%d”, m, y ) ;
while ( 1 )
{
normaldays ____ = ( y - 1 ) * 365L ;
c__a__lender
gotorc ( 20, 35
) ;
printf ( ”Rt-Next mth…” ) ;
ch = getkey( ) ;
switch ( ch )
{
case 77 :
m++ ;
if ( m 12 )
{
y++ ; m = 1 ;
__}__ }
}
}
......CCaalleennddaarr
Next year
Prev.
mth Next
Prev. year
mth
12. main( )
{
AArrrraayy ooff SSttrruuccttuurreess
struct employee
{
char n ;
int a ;
float s ;
} ;
struct employee e[ ]
= {
{ ’A’, 23, 4000.50 } ,
{ ’X’, 27, 5000.00 } ,
{ ’Y’, 28, 6000.75 }
} ;
int i ;
for ( i = 0 ; i = 2 ; i++ )
printf ( ”%c %d %f”, e [ i ]
}
.n, e[ i ].a, e[ i ].s ) ;
13. Keyword eemmppllooyyeeee
Structure
name/
struct
{
tag
char n ;
int a ;
float s ;
} ;
struct employee e1, e2, e[ 10 ] ;
Structure elements/
members
Structure
variables Array of
structures
14. Conclusion
A structure is usually a collection of
dissimilar elements.
Structure elements are always stored in
adjacent memory locations.
struct employee e[ 3 ] ;
A 23 400.50 X 27 500.00 Y 28
600.75
401 408 415
15. AArrrraayy ooff SSttrruuccttuurreess
struct employee e[ ] = { ... } ;
char *p ;
Ptr. to
structure
struct employee e[ 3 ] ;
A 23 400.50 X 27 500.00 Y 600.75
401 408 415
q = e ; r = e ;
p = e ;
p++ ;
printf ( ”%u”, q ) ;
28
struct employee *q ;
struct employee (*r )[3] ;
q++ ; r++ ;
printf ( ”%u”, p ) ;
printf ( ”%u”, r ) ;
440022
440088
442222
Array of
ptrs.