Software development can be quite challenging. To solve a problem the programmer must break down the problem to the smallest factors possible. You really have to think like a machine.
I notice that you are using pretty much the shortest possible identifiers possible. Although there is less code, the code is not very readable. It's a tremendous help to anyone reading your code (including yourself, and however good a programmer you are, you will spend more time reading your code than writing) that you use meaningful variable and method names. Most IDEs will autocomplete identifiers for you, so don't be afraid of being to descriptive.
It seems as though you have the mod operator backwards. Just remember that mod is a division. Whatever it is you want to divide goes on the left, and what you want to divide by goes on the right. Mod returns the remainder of this division. 7%8=7, 8%7=1, 7%7=0.
Also, you have a nested for loop (for loop inside of a for loop). These can be very useful for iterating a grid with x and y for example (this calendar view does not need one). The problem with your nested loop is that you are using the same variable to iterate both loops. Although the syntax is legal, it's easy to setup some errors doing this. The for loop inside is changing the same variable that the outside loop is using. It's best to avoid having any code other than the for loop itself modify the iterator.
I notice that you are using pretty much the shortest possible identifiers possible. Although there is less code, the code is not very readable. It's a tremendous help to anyone reading your code (including yourself, and however good a programmer you are, you will spend more time reading your code than writing) that you use meaningful variable and method names. Most IDEs will autocomplete identifiers for you, so don't be afraid of being to descriptive.
It seems as though you have the mod operator backwards. Just remember that mod is a division. Whatever it is you want to divide goes on the left, and what you want to divide by goes on the right. Mod returns the remainder of this division. 7%8=7, 8%7=1, 7%7=0.
Also, you have a nested for loop (for loop inside of a for loop). These can be very useful for iterating a grid with x and y for example (this calendar view does not need one). The problem with your nested loop is that you are using the same variable to iterate both loops. Although the syntax is legal, it's easy to setup some errors doing this. The for loop inside is changing the same variable that the outside loop is using. It's best to avoid having any code other than the for loop itself modify the iterator.
Code:
int daysInMonth = 30, firstDay = 3;
// display a header
printf (" S\t M\t T\t W\t T\t F\t S");
// insert some blank days
for (int i=1; i<firstDay; i++)
printf ("\t");
// iterate all the days of the month
for (int thisDay=1; thisDay<=daysInMonth; thisDay++) {
// display the day and follow it with a tab
printf ("%2d\t", thisDay);
// if this happens to be a Saturday (column is a multiple of 7
// we can find out the column by adding thisDay and firstDay
if ( (thisDay+firstDay-1) % 7 == 0) // firstDay is 1 to 7, so we must subtract 1
// then we'll need to break the line
printf ("\n");
}