工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 3656|回复: 9

c语言编程

[复制链接]
发表于 2006-4-2 13:29 | 显示全部楼层 |阅读模式
我想用C语言编这样一个程序:当输入任意的年份和月份时,屏幕能显示该月的月历。
各位变成大虾可否帮帮我。
发表于 2006-4-2 17:18 | 显示全部楼层
不知道楼主做了有啥用处?
作业,兴趣爱好?还是纯粹无聊?
回复

使用道具 举报

发表于 2006-4-2 23:26 | 显示全部楼层
以前写过一个,难度在算法,但是只要知道那个年月的关系也就不难了.
回复

使用道具 举报

发表于 2006-4-3 21:52 | 显示全部楼层
你想在屏幕上怎么显示?

最难是这个。。
回复

使用道具 举报

发表于 2006-4-3 22:23 | 显示全部楼层
楼上说的是这个吗?
假设这个月的1号是星期二,并且这个月有30天.

  1. #include<iostream>
  2. using namespace std;

  3. int main()
  4. {
  5.     char *weeks[]={"日","一","二","三","四","五","六"};
  6.     for(int i=0;i<7;i++)cout<<weeks[i]<<"\t";
  7.     cout<<endl;
  8.     int firstDay=2;//如果是星期天则为0
  9.     for(int i=0;i<firstDay;i++)cout<<"\t";
  10.     for(int i=1;i<31;i++)
  11.     {
  12.             cout<<i<<"\t";
  13.             if((i+firstDay)%7==0)cout<<endl;
  14.     }
  15. }
复制代码

效果图:

日      一      二      三      四      五      六
                1       2       3       4       5
6       7       8       9       10      11      12
13      14      15      16      17      18      19
20      21      22      23      24      25      26
27      28      29      30
回复

使用道具 举报

 楼主| 发表于 2006-4-5 12:28 | 显示全部楼层
不是那么简单的,我需要的是任意年月的日期表.例如:我输入2006年4月,就会把这一年这一月的日期表输出.
只是想试一下,自己无聊的时候试了一下,但老是无法得到自己满意的答案~~~~~
所以各为大虾帮一下咯~~~~
回复

使用道具 举报

发表于 2006-4-6 01:19 | 显示全部楼层

给个vbs参考程序,没多检验,请大家指正

'make by ljy
'2006-4-6
yea = Inputbox ("请输入年份","日历测试",2006)
If yea > 9999 Or yea < 0 Then
Msgbox "年份输入错误"
Wsh.Quit
End If

mon = Inputbox ("请输入月份","日历测试",1)
If mon > 12 Or mon < 0 Then
Msgbox "月份输入错误"
Wsh.Quit
End If

dat = mon & "/" & "1/" & yea           '以一号计算是星期几
olddate = "31/1/0000"                  '以0000年1月31日求每个月的天数
diff = DateDiff("m",olddate,dat)
endat = DateAdd("m",diff,olddate)
lastday = Right(endat,2)                 '月份的最后一天是几号
intDay = DatePart("w", dat)             '月份的第一天是星期几
calendar = "Sun Mon Tue Wen Thu Fri Sat" & vbCrLf

For i = 1 to intDay-1
calendar = calendar & "    "
Next

For i = 1 to lastday
  If i < 10 Then
  calendar = calendar & i & "   "
  Else
  calendar = calendar & i & "  "
  End If
  If (intDay + i - 1) Mod 7 = 0 Then
     calendar = calendar & vbCrLf
  End If
Next
msgbox calendar,,"日历测试"
回复

使用道具 举报

发表于 2006-4-6 03:28 | 显示全部楼层

C的,没检查,可能有bug

#include<stdio.h>

static int Dtab [2][13] =
{
  {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
  {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
};
int main()
{
int year,mon,date=1,day,last,i,temp;
scanf("%d,%d",&year,&mon);
if(year>9999||year<0||mon>12||mon<0)
{
         printf("输入错误\n");
     return 1;
}
temp = date + 2*mon + 3*(mon+1)/5 + year + year/4 - year/100 + year/400;
day=temp%7+1;

if((year)%4 == 0 && (year)%100 != 0 || (year)%400 == 0)
   last = Dtab[0][mon];
else last = Dtab[1][mon];
printf("Sun Mon Tue Wen Thu Fri Sat\n");
if(day != 7)
{
         for(i=1;i<day+1;i++)
     printf("    ");
}
for(i=1;i<=last;i++)
    {
            if(i<10) printf("%d   ",i);
                else printf("%d  ",i);
        
        if((i+day)%7==0)
          printf("\n");
    }
printf("\n");
return 0;
}
回复

使用道具 举报

发表于 2008-11-22 23:41 | 显示全部楼层
强人[em021]
回复

使用道具 举报

发表于 2008-12-22 11:21 | 显示全部楼层
都很强的~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2024-6-6 02:37

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表