Skip to content

Instantly share code, notes, and snippets.

@kimitoboku

kimitoboku/16-192558.c

Last active Dec 19, 2015
Embed
What would you like to do?
年と月を貰ってカレンダーを表示的な課題
#include<stdio.h>
#include<time.h>
const int monthDay[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int getMonthFirestDayOfWeek(int y,int m);
int main(int argc, char *argv[]){
int i;
int m = 7;
int week = getMonthFirestDayOfWeek(2013,m);
for (i=0; i < week; ++i){
printf (" ");
}
i = 1;
for (;;){
for (; week < 7; week++){
printf (" %2d",i++);
if (i == monthDay[m]+1){
return 0;
}
}
week = 0;
puts ("");
}
return -1;
}
int getMonthFirestDayOfWeek(int y,int m){
struct tm time_in,*local;
time_t times;
time_in.tm_year = y - 1900;
time_in.tm_mon = m -1;
time_in.tm_mday = 1;
time_in.tm_hour = 1;
time_in.tm_min = 0;
time_in.tm_sec = 0;
time_in.tm_wday = 0;
time_in.tm_yday = 0;
times = mktime (&time_in);
local = localtime (&times);
return local->tm_wday;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment