| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 344 人关注过本帖
标题:c语言问题
只看楼主 加入收藏
mkl34367803
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-9-6
结帖率:20%
收藏
已结贴  问题点数:10 回复次数:4 
c语言问题
我自己写的一个计算一年中某一天在该年是第几天:
#include<stdio.h>
void main()
{
    int y,m,d,total=0;
    printf("please input y空格m空格d:");
    scanf("y/m/d=%d%d%d",&y,&m,&d);
    if(m==1)
        printf("total=%d",d);

    if(m==2)
        printf("total=%d",d+31);

    if(m==3)
    {
        if(y%4==0&&(y%100!=0)||y%400==0)
            printf("total=%d",d+31+29);
        else
            printf("total=%d",d+31+28);
    }

        if(m==4)
    {
        if(y%4==0&&y%100!=0||y%400==0)
            printf("total=%d",d+31+29+31);
        else
            printf("total=%d",d+31+28+31);
    }

        if(m==5)
    {
        if(y%4==0&&y%100!=0||y%400==0)
            printf("total=%d",d+31+29+31+30);
        else
            printf("total=%d",d+31+28+31+30);
    }

        if(m==6)
    {
        if(y%4==0&&y%100!=0||y%400==0)
            printf("total=%d",d+31+29+31+30+31);
        else
            printf("total=%d",d+31+28+31+30+31);
    }

        if(m==7)
    {
        if(y%4==0&&y%100!=0||y%400==0)
            printf("total=%d",d+31+29+31+30+31+30);
        else
            printf("total=%d",d+31+28+31+30+31+30);
    }

        if(m==8)
    {
        if(y%4==0&&y%100!=0||y%400==0)
            printf("total=%d",d+31+29+31+30+31+30+31);
        else
            printf("total=%d",d+31+28+31+30+31+30+31);
    }

        if(m==9)
    {
        if(y%4==0&&y%100!=0||y%400==0)
            printf("total=%d",d+31+29+31+30+31+30+31+31);
        else
            printf("total=%d",d+31+28+31+30+31+30+31+31);
    }

        if(m==10)
    {
        if(y%4==0&&y%100!=0||y%400==0)
            printf("total=%d",d+31+29+31+30+31+30+31+31+30);
        else
            printf("total=%d",d+31+28+31+30+31+30+31+31+30);
    }

        if(m==11)
    {
        if(y%4==0&&y%100!=0||y%400==0)
            printf("total=%d",d+31+29+31+30+31+30+31+31+30+31);
        else
            printf("total=%d",d+31+28+31+30+31+30+31+31+30+31);
    }

        if(m==12)
    {
        if(y%4==0&&y%100!=0||y%400==0)
            printf("total=%d",d+31+29+31+30+31+30+31+31+30+31+30);
        else
            printf("total=%d",d+31+28+31+30+31+30+31+31+30+31+30);
    }

}
搜索更多相关主题的帖子: please c语言 include total 
2012-09-06 21:42
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:3 
So What
2012-09-06 21:46
mkl34367803
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2012-9-6
收藏
得分:0 
运行不起啊
2012-09-07 22:45
董晓
Rank: 1
等 级:新手上路
帖 子:1
专家分:3
注 册:2009-12-30
收藏
得分:3 
弹错吗?还是????你可以把结果贴出来!!!
2012-09-07 23:40
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:3 
我觉得这个语句可能就有点问题:
scanf("y/m/d=%d%d%d",&y,&m,&d);
这样你得输入
y/m/d=2012 9 8
才行。不会你就这么想的吧?
2012-09-08 00:16
快速回复:c语言问题
数据加载中...
 
   



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

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