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
What is data structure in c language?
What are the 5 types of organizational structures?
What is 1d array in c?
How many bytes are occupied by near, far and huge pointers (dos)?
What are actual arguments?
Write a program to check prime number in c programming?
What are the types of type specifiers?
What does typedef struct mean?
Explain indirection?
What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)?
What is the meaning of 2d in c?
What is a pointer variable in c language?
What are the different categories of functions in c?
What will the preprocessor do for a program?
What is bin sh c?