write a program to print calender using for loop.




write a program to print calender using for loop. ..

Answer / abdul rahman

// Callender for 2011
#include<stdio.h>

#include<string.h>
char* month(int);
main()
{

int mm,d,m,st,start=6,count,day=0;
for(m=1;m<=12;m++)
{printf("\n");
puts(month(m));
printf("\n");
printf("su\tmo\ttu\twe\tth\tfr\tsa\n");
for(st=start;st>0;st--)
{

printf("\t");
day++;
}

if(m<8)
{

if(m%2)
count=31;
else
{count=30;
if(m==2)
count=28; }
}
else
{
if(m%2)
count=30;
else
count=31;
}
for(d=1;d<=count;d++)
{
if(start==7)
{start=0;
printf("\n");
}

printf("%d\t",d);
start++;
}
printf("\n");
}

}
char* month(int a)
{
switch (a)
{
case 1:return("Jan");

case 2:return("Feb");

case 3:return("Mar");

case 4:return("Apr");

case 5:return("May");

case 6:return("Jun");

case 7:return("Jul");

case 8:return("Aug");

case 9:return("Sep");

case 10:return("Oct");

case 11:return("Nov");

case 12:return("Dec");

default: return(0);
}

}

Is This Answer Correct ?    9 Yes 0 No

Post New Answer

More C Interview Questions

What are the 4 data types?

0 Answers  


Can you subtract pointers from each other? Why would you?

0 Answers  


What is difference between structure and union in c?

0 Answers  


What is static memory allocation? Explain

0 Answers  


#define DCHAR char* typedef char* TCHAR; if using these following variables will be declared like DCHAR ch1, ch2; TCHAR ch3, ch4; then what will be types of ch1, ch2, ch3 and ch4?

6 Answers   NDS,






What is alloca() and why is its use discouraged?

1 Answers  


What math functions are available for integers? For floating point?

0 Answers  


1. Write a program to reverse every second word in a given sentence.

1 Answers  


Which is the memory area not included in C program? give the reason

0 Answers   IBM, TCS,


If an old women's age is the same as her three grand daughters i,mean the number of days old child=the no of weeks old child=no of months old child .The total yrs of all these ppl is 114 yrs...then how old is the old woman? the yr has 365 days..and 30 days each month.

1 Answers   TCS,


What's a good way to check for "close enough" floating-point equality?

0 Answers   Celstream,


what does the following function print? func(int i) { if(i%2)return 0; eale return 1; } main() { int =3; i=func(i); i=func(i); printf("%d",i);}

9 Answers   TCS,


Categories