Programming growth diary ———— guessing number games

Source: Internet
Author: User

Simulates guessing a number game, prompting the user to enter a range of digits each time.

#include  <stdio.h> #include  <stdlib.h>//guess number game int main () {Int i=0;int num  =0,ret=0,choose=0;int min=1,max=100;flag:srand ((unsigned) time (NULL)),  ret=rand ()%100+1;while (1 {printf ("Please enter a number between%d~%d: \ n", Min,max),     scanf ("%d", &num);    if (num< RET)    {   min=num;   printf ("Guess small, between%d~%d \ n", Min,max);    }   if (Num>ret)    {   max=num;    printf ("Guess big, between%d~%d \ n", Min,max);    }   if (Num==ret)    {    printf ("Guess right, do you want to continue?") \n1. is   2. No \ n "); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d ", &choose);    switch ( Choose)    {   case 1:              min=1;             max=100;  goto flag;  break;   case 2:       exit (0);       break;      }    }}return 0;}

This focus is on the generation of random numbers, and the random number produced is different each time, using Ret=srand ((unsigned) (NULL))

Note that header files should be added #include<stdlib.h>

This article from "10954937" blog, declined reprint!

Programming growth diary ———— guessing number games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.