Your code will stay formatted properly, only if you click on the [CODE ] icon in the editing window, and paste your code right between the code tags that the editor gives you:
[CODE ]
<YOUR CODE GOES HERE>
[/CODE ]
Take a look at this. I couldn't quite grasp the logic that was involved in your program.
#include<stdio.h>
#define p printf
#define s scanf
int main()
{
int totalDays,day,i, j, r, c, firstDay;
//clrscr();
printf("\n\n\n");
p("Input Number of days in a month:");
s("%d",&totalDays);
p("Input the first day of the month:");
s("%d",&firstDay);
p(" Sun Mon Tues Wed Thurs Fri Sat\n");
for(r=0,day=0;r<5;r++)
{
if(r==0) { //printing the first row only
for(j=0;j<7;j++) {
if(j==2 || j==4 || j==5) //handles days with 4 letters, etc.
putchar(' '); //I don't like using tabs
if(j<firstDay)
printf(" "); //as you can tell ;)
else
printf(" %2d ", ++day);
}
putchar('\n');
}
for(c=0;c<7;c++) { //prints all the other rows
if(++day>totalDays)
break;
if(c==2||c==4 ||c==5)
putchar(' '); //about the same as the first row
printf(" %2d ", day);
}
printf("\n");
}
getch();
return 0;
}