| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 853 人关注过本帖
标题:又要麻烦高手们了~~~自己写的一个小程序,不知道错在哪里
取消只看楼主 加入收藏
tiw
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2008-2-13
收藏
 问题点数:0 回复次数:2 
又要麻烦高手们了~~~自己写的一个小程序,不知道错在哪里
#include<stdio.h>
int b(long year, long presentyear,int month,int day)//计算天数
{  int sum=0,leap=0;
   if(month==2&&day==29)
  {
      if(presentyear%400==0||(presentyear%4==0&&presentyear%100!=0))
   {
      while((presentyear+=4)<=year)
    {
        sum+=5;
    }
    return sum;
   }
   else
   {
       printf("had not the day!\n");
       return -10;
   }

  }
  else if(month==1||(month==2&&(day!=29)))
  {
     while(presentyear++<year)
   {

   if(presentyear%400==0||(presentyear%4==0&&presentyear%100!=0))/*判断是不是闰年*/
leap=1;
else
leap=0;
if(leap==1)/*如果是闰年,应该多1天*/
sum+=2;
else
sum+=1;
 }

 return sum;
 }
  else
  {
    while((presentyear+=1)<=year)
   {

   if(presentyear%400==0||(presentyear%4==0&&presentyear%100!=0))/*判断是不是闰年*/
leap=1;
else
leap=0;
if(leap==1)/*如果是闰年,应该多1天*/
sum+=2;
else
sum+=1;
 }

 return sum;

}
}

int  c(int week,long year,long presentyear,int month,int day)//计算当天星期
{   int n;
    n=b(year,presentyear,month,day)+week;
    return n;
}




void main()
{   int presentyear,age,year,presentage,month,day,week,flag;
    printf("this program gives your age in a year ,and your birthday week in that year\n");
    printf("what year is this?\n");
    scanf("%d",&presentyear);
    printf("which year you want know?\n");
    scanf("%d",&year);
    printf(" what is your present age?\n");
    scanf("%d",&presentage);
    printf("what is month and day\n");
    scanf("%d%d",&month,&day);
    printf("what is your birthday (month,day)and which week in that day?\n");
    printf("monday=1\ttuesday=2\twednesday=3\tthusday=4\tfriday=5\tsturday=6\tsunday=7\n");
    scanf("%d",&week);
    age=year+presentage-presentyear;
    printf("you well be %d year in the %d\n",age ,year);
    printf("your birthday month %d day %d is \n",month,day);
    flag=c(week,year,presentyear,month,day);
    switch(flag%7)
    {   case 0:printf("%d\n",7);break;
        case 1:printf("%d\n",1);break;
        case 2:printf("%d\n",2);break;
        case 3:printf("%d\n",3);break;
        case 4:printf("%d\n",4);break;
        case 5:printf("%d\n",5);break;
        case 6:printf("%d\n",6);break;
        default:printf("error!\n");break;
     }


}

[[it] 本帖最后由 tiw 于 2008-5-29 16:26 编辑 [/it]]
搜索更多相关主题的帖子: 麻烦 
2008-03-23 16:35
tiw
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2008-2-13
收藏
得分:0 
哦,谢谢~~~~~~~~~~
2008-03-23 19:32
tiw
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2008-2-13
收藏
得分:0 
这个程序经过大家的帮助,可以运行了,但算法上有点问题!~~~
2008-03-25 19:06
快速回复:又要麻烦高手们了~~~自己写的一个小程序,不知道错在哪里
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026180 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved