啊哈磊_编程从这里起步

标题: 2分钟的倒计时 [打印本页]

作者: shly900928    时间: 2013-12-10 23:07
标题: 2分钟的倒计时

1. 请尝试编写一个 2 分钟的倒计时。形如:2:00 1:59 1:58……1:00 0:59 0:58……0:02 0:01 0:00
作者: 梦中的婚礼    时间: 2013-12-10 23:13
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#include <malloc.h>
#include <dos.h>
main()
{
  system("title 关机定时程序");
  system("mode con: cols=40 lines=20");
  system("cls");
  printf("\n\n");
  printf("---------------------------\n\n");
  printf("\n\n您想多久后关机?(秒)请输入:");
  char a[99]="shutdown -s -t ";
  char b[99];
  scanf("%s",b);
  system(strcat(a,b));
}


注:可能会有多余的头文件,但是不影响编译结果。
作者: HUIH    时间: 2013-12-13 22:33
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>

int main()
{
        int t=0;
    printf("2:00\n");
    Sleep(1000);
        do{
                t+=1;
        if(t==120){
                        printf("0:00\n");
            break;
        }
        int _t=-1*(t-120);
        if(_t<60){
                        printf("0:%d\n",_t);
        }else if(_t==120){
                        printf("0:00\nTime over\n");
            break;
        }else {
                        printf("1:%d\n",_t%60);
        }
        Sleep(1000); //一秒后继续报时
    }while(1);
    system("pause");
    return 0;
}
作者: 哈哈的printf    时间: 2014-7-8 17:58

#include <windows.h>
int main()
{
       
    int a;
    a=120;
    printf("两分钟倒数,五秒后开始倒数\n");
    printf("__________\n");
    Sleep(5000);
    system("color 5f");
    while(a<=120)
   {
    system("cls");
    printf("%d\n",a);
    Sleep(1000);
    a=a-1;
   }
    system("pause");
        return 0;
}
[mw_shl_code=c,true][/mw_shl_code]




欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2