write a program to print calender using for loop.


Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

cavium networks written test pattern ..

3592


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

642


How can I do serial ("comm") port I/O?

683


Can we declare variable anywhere in c?

533


What are different types of pointers?

561






What is the size of array float a(10)?

651


What does a function declared as pascal do differently?

603


Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.

1718


How can you find the exact size of a data type in c?

597


What is atoi and atof in c?

612


What is an array in c?

592


Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

648


What does %c mean in c?

643


Explain the difference between null pointer and void pointer.

663


What is the function of this pointer?

668