Warning: Declaration of action_plugin_changes::register($controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /volume1/web/dokuwiki/lib/plugins/changes/action.php on line 0 Warning: Declaration of syntax_plugin_code::handle($aMatch, $aState, $aPos, &$aHandler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /volume1/web/dokuwiki/lib/plugins/code/syntax.php on line 42 Warning: Declaration of syntax_plugin_code::render($aFormat, &$aRenderer, &$aData) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /volume1/web/dokuwiki/lib/plugins/code/syntax.php on line 42 c_rand_ext [Protocol Engineering Lab.]

User Tools

Site Tools


c_rand_ext
/* rand_ext.c: guess the number */
#include <stdio.h>      /* printf, scanf, puts, NULL */
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
 
int main(void)
{
    int secret, guess;
 
    /* initialize random seed */
    srand(time(NULL));
 
    /* generate secret number between 1 and 10 */
    secret = rand() % 10 + 1;
 
    do {
        printf ("Guess the number (1 to 10): ");
        scanf ("%d",&guess);
        if (secret < guess) puts ("The secret number is lower");
        else if (secret > guess) puts ("The secret number is higher");
    } while (secret != guess);
 
    puts ("Congratulations!");
 
    return 0;
}
c_rand_ext.txt · Last modified: 2015/02/07 18:38 by jonghyouk