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

Can I initialize unions?

594


Explain how can you check to see whether a symbol is defined?

663


GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)

684


Write a program of prime number using recursion.

619


How is a structure member accessed?

585






Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

1497


What is a floating point in c?

604


What does c mean before a date?

592


What will the code below print when it is executed?   int x = 3, y = 4;         if (x = 4)                 y = 5;         else                 y = 2;         printf ("x=%d, y=%d ",x,y);

1358


What is masking?

637


How will you declare an array of three function pointers where each function receives two ints and returns a float?

782


What are predefined functions in c?

568


List a few unconditional control statement in c.

560


Is c a great language, or what?

604


main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none

726