搜索
楼主: tomatokely
打印 上一主题 下一主题

P167两分钟的倒计时该怎么编啊?

[复制链接]
16#
发表于 2013-3-15 22:00:24 | 只看该作者
#include <stdio.h>
#include <windows.h>
int main()
{
        int a=120;
    while(a>=0)
    {
                printf("%d:%02d\n",a/60,a%60);
        system("cls");
        a=a-1;
     }
        sleep(5000);
        return 0;
}
17#
发表于 2013-8-15 15:00:15 | 只看该作者
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
        int time=120,minutes,seconds;
    while(time>=0)        /*循环到时间为0*/
        {
                system("cls");
        //hours = (time/3600)%24 ;        //计算小时分钟秒
        minutes =( time / 60)%60 ;        
        seconds = time % 60 ;
        if(seconds<10)
                        printf("%d:0%d",minutes,seconds);
        else
                        printf("%d:%d",minutes,seconds);
        time--;
        Sleep(100) ;        /*暂停1秒*/
     }
    system("pause");
        return 0;
}
18#
发表于 2016-9-7 20:23:00 | 只看该作者
[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
        int a;
    a=120;//两分钟就是120秒;
    system("color 0a");//改个好看的颜色;
    while(a>=0)//秒倒数到0就停止咯;
    {
                system("cls");//每次循环前不管三七二十一清屏一下;
                printf("%.2d:%.2d",a/60,a%60);//%.2d代表显示两位数,a/60代表分钟,a%60代表秒钟;
                a=a-1;//每次循环秒数减一;
        Sleep(1000);//当然要延迟1秒钟才能循环;
    }
        system("pause");
        return 0;
}
[/mw_shl_code]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表