| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2761 人关注过本帖
标题:用C语言编出2008年北京奥运会倒计时,天天.时时.分分.秒秒?
取消只看楼主 加入收藏
yelusu
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-4-15
收藏
 问题点数:0 回复次数:2 
用C语言编出2008年北京奥运会倒计时,天天.时时.分分.秒秒?
想了半天,不知道从何处入手。大家帮忙提示点思路咯!
不知道利用死循环能能编出来?

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int i_sleep(int n)//延迟n秒函数
{
    time_t start,end;
    start=time(NULL);
    end=time(NULL);
    while(end-start<n)
    {
        end=time(NULL);
    }
    return 0;
}

int showtime()
{
        struct tm timestru,*tmtime;
        time_t endtime, curtime;
        long ttime;

        timestru.tm_year = 2008 - 1900;
        timestru.tm_mon = 8 - 1;         
        timestru.tm_mday = 8;        
        timestru.tm_hour = 20;
        timestru.tm_min = 0;
        timestru.tm_sec = 0;
      
        endtime = mktime(&timestru);
        curtime = time(NULL);
        ttime = endtime - curtime;
        tmtime = localtime(&curtime);
      
        printf("\n\n\n");
        printf("\t\t ———————————————————————— \n");
        printf("\t\t|        2008北京奥运倒计时       |\n");
        printf("\t\t|———————————————————————|\n");
        printf("\t\t|     当前时间 %04d年%02d月%02d日 %02d时%02d分%02d秒     |\n",
                tmtime->tm_year + 1900, tmtime->tm_mon + 1, tmtime->tm_mday ,
                tmtime->tm_hour, tmtime->tm_min, tmtime->tm_sec);
        printf("\t\t|———————————————————————|\n");
        printf("\t\t|    距北京奥运 %04d年%02d月%02d日 %02d时%02d分%02d秒    |\n",
                timestru.tm_year + 1900, timestru.tm_mon + 1, timestru.tm_mday,
                timestru.tm_hour, timestru.tm_min, timestru.tm_sec);
        printf("\t\t|———————————————————————|\n");      
        printf("\t\t|           还有%3d天%02d时%02d分%02d秒              |\n",
                ttime/86400, ttime%86400/3600, ttime%86400%3600/60, ttime%86400%3600%60);
        printf("\t\t ———————————————————————— \n\t\t");
      
        return 0;        
}

int main(int argc, char *argv[])
{
        while(1)
        {
                system("cls");
                showtime();
                i_sleep(1);
        }
        return 0;
}

结果:
图片附件: 游客没有浏览图片的权限,请 登录注册


以下是我找的程序,有一处错误!请高手帮忙解决了!
题目在以下附件里:
yelusu.rar (182.08 KB)



[[it] 本帖最后由 yelusu 于 2008-5-27 17:22 编辑 [/it]]

[[it] 本帖最后由 yelusu 于 2008-5-27 17:24 编辑 [/it]]
搜索更多相关主题的帖子: 北京奥运会 C语言 分分 倒计时 include 
2008-05-21 20:37
yelusu
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-4-15
收藏
得分:0 
咋就没人会呢!
用C语言好像是难了!
不知道用C++能不能做出来!
2008-05-22 13:10
yelusu
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-4-15
收藏
得分:0 
写的确实不错!
只不过不是汇编语言写的有点遗憾!
time函数我也没学过!
2008-05-27 17:20
快速回复:用C语言编出2008年北京奥运会倒计时,天天.时时.分分.秒秒?
数据加载中...
 
   



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

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