C-language guessing game-generating a random number

Source: Internet
Author: User

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

int main (int argc, const char * argv[]) {

Insert code here ...

printf ("Hello, world!\n");

int a,b,i;

{

Srand ((unsigned int) time (0));

b = rand ()%100 + 1;

printf ("%d\n", b);//hides randomly generated numbers.

}

Generate a random number

while (1) {

printf ("Insert the number you thinking, please\n");

scanf ("%d", &a);//scanf There is no impurity inside, if there is a space or something will cause the input of the first data can not run, starting from the second data to run.

i=i+1;

if (a>b)

{

printf ("Too big, smaller would be better.") \ n ");

}

else if (a<b) {

printf ("Too small, you should think of a bit more \ n");

}

else{

printf ("Congratulations. Correct!!! You guessed it for%d times.!!! You're so smart, "I";

break;//no break will keep running

}

}

int a,b,i;

//

Srand ((unsigned int) time (0));

Srand ((unsigned int) time (0));

//

b = rand ()%100 + 1;

printf ("%d\n", b);

for (i=0; i<100; i++) {

printf ("Please enter a number \ n");

scanf ("%d", &a);

if (a>b) {

printf ("??, the number you entered is big");

//            }

else if (a<b)

printf ("??, the number you entered is small");

Else

{printf ("Congratulations, correct");

Break

//            }

//        }

return 0;

}

/* Generates a random number complete code

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

int main ()

{

Srand ((unsigned int) time (0));

int a[20];

for (int i = 0; i <; i++)

{

A[i] = rand ()%100 + 1;

printf ("%d\n", A[i]);

}

return 0;

} */

C-language guessing game-generating a random number

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.