栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言循环结构与时间函数用法实例教程

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言循环结构与时间函数用法实例教程

本文实例展示了C语言循环结构与时间函数用法,对于C语言的学习来说是非常不错的参考借鉴材料。分享给大家供大家参考之用。具体如下:

完整实例代码如下:



#include 
#include 
#include       
#include  
#include 

int main(void)
{
    char nextGame = 'Y';      
    bool correct = false;      
    int counter = 0; 
    int seq_len = 0; 
    int input_num = 0;
    time_t seed = 0; 
    //int i = 0;     

    clock_t start_clock = 0;    
    int time_taken = 0;

    printf("Here is a simon game for training memory ability .n");
    printf("nThe screen will show a number sequence for 1 second , ");
    printf("then the sequence will disappear. You are suggested to "
 "input the same sequence to pass the game.n");
    printf("nNotice this: each digit is seperated by a space. n");
    printf("nNow press Enter to play .. Good luck !n");
    scanf("%c",&nextGame); //Waiting for user's input

    do
    {
 correct = true ;
 counter = 0 ;  
 seq_len = 2 ;  
 time_taken = clock();

 while(correct)
 {
     
     seq_len += (counter++ % 3 == 0);
     //if "==" expression is true,returns 1; else returns 0

     
     seed = time(NULL);

     
     srand((unsigned int)seed);
     //initialize the seed for rand() function
     for(int i=0; i

本文实例源自国外网站,为一个数字游戏,感兴趣的读者可以调试运行一下,体会代码的原理,加深对C语言循环结构域时间函数的认识。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/65544.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号