Decision Statements 111
case 11:
a*5;
j~30;
break;
case 12:
a*7;
/*3i;
break;
default:
printf ("aa Invalid Month");
exit();
I
/* Starting day is to be adjusted under the respective day * /
printf (nnn");
printf ("tttMonth - %d - 2001nn",m);
printf (u SUN MON TUE WED THU FRI SATnn");
switch (a)
I
case 1 :
printf rt% d",i);
break;
case 2 :
printf rtt% d",i);
break;
case 3 :
printf (ttt%d",i);
break;
case 4 :
printf ("tttt%d",in
break;
case 5 :
printf ("ttttt%d",i) ; .
break;
case 6 :
printf(" tttttt%d",i);
break;
case 7 :
printf (" ttttt tt%d",i);
break;
/
h=8-a; /* The starting day is subtracted from 8 */
112 Programming and Data Structures
fo r (i=2rf<=hf-i++) I* To display the first row */
>.*ir.tfC %d",i);
printf ("n");
fo r (i=h+l; i<=j,-i++) /* To continue with second row onwards */
I
if(b==8) /* To terminate the line after every week */
I
printf ("n");
b=l;
I
printf rt%d",i);
b++;
I
getchO;
Q CTYUT;
Enter Month No. of Year 2001: 1
SUN MON TUE WED THU FRI SAT
1
2
3 4 5 6 7
8
9
10 11 12 13 14 15 16 17
18 19
20
21
22
23
24 25
26
27 28 29 30 31
Explanation This program prints the days of a given month of a year 2001 in the calendar form. This
will be done without the help of system resources. The month number is to be entered by the user. It is
passed to first swi tch () structure. This structure finds the 1st day of the month in numeric form and
the number of days present in that month. These values are assigned to a & j respectively. Here,
Sunday to Monday refers to 1 to 7 values respectively. The p rin t f () functions and second swi tch ()
structure perform printing of the dates column wise. The variables i, b are initialized to 1.
The second sw itch () structure defines the starting column and prints the value of ' i ' that is
always 1. The value of ' h 7 (8 minus 'a') determines the number of dates to be printed in the first row.
This task is performed by the first fo r loop. In the second fo r loop h is increased to 1 and loop
continues up to the number of day i.e. j . To break up dates row wise, i f statement compares the value
of variable ' b ' with 8. If b=8 then line breaks and ' b 7 again initializes to 1. Whenever b=8, line is
broken and whole dates of the month are arranged in the calendar form.
5.27 Write a program to convert decimal to hexadecimal number.
# include <stdio.h>
# include <conio.h>
# include <process.h>
void main ()
{
in t x,y *30 ,z ;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.108.175