プロが教えるわが家の防犯対策術!

C言語のプログラミングについて教えてください!
何度か質問してそれに対しての回答を元にまた作り直したものです。
C言語のプログラミングで年と月を入力するとその月のカレンダーを表示するプログラムを完成させて貰いたいです!
西暦一年一月一日を月曜日としてカレンダーは日曜日から始まるものです!


#include <stdio.h>

int main(void){

int month_day[12]={31,28,31,30,31,30,31,31,30,
31,30,31};//それぞれの月の日の配列
if(month==2){
if(year%400 == 0 || (year%100 != 0 && year%4 == 0)){
month_day[1]=29;
  }
}

int cut = 0;
int year,month,i;

int total=0;

scanf("%d",&year);//年を入力
printf("年を入力してください",year);//入力された年の値を出力

scanf("%d",&month);//月を入力
printf("月を入力してください",month);//入力された月の値を出力

printf(" SUN MON TUE WED THU FRI STA \n")
\\曜日を出力
total=total+1;

for(i=1; i<year; i++){
total+=365;

if(year%400==0 || (year%100 != 0 && year%4 == 0))
total++;

for(i=0;i<month-1;i++){
total+=month[1];

if(year%400==0 || (year%100 != 0 && year%4 == 0 && month != 1 &&month !=2)){
total++;
}

for(i=1;cnt=0; i<=total%7; i++, cnt++)
printf(" ");
for(i=1; i<=month[month-1]; i++,cnt++)

if(cnt %7 == 0)
printf("\n");
printf("%3d",i);
}
printf("\n");
return 0;
}

A 回答 (3件)

律儀に何年か計算しているみたいだけど、


400年の総日数は7で割り切れるから、
400年分の繰り返しだけで曜日の計算できますよ。
    • good
    • 0

TIME関数の再発明ですか。


ご苦労様です。
    • good
    • 1

「完成させて貰いたい」というのは, 一般的な日本語では「質問」の範疇に入らないんだけどなぁ.



で「質問」は何?
    • good
    • 7

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!