In C programming, how to make the computer randomly output an integer of 1 9

Updated on technology 2024-06-14
8 answers
  1. Anonymous users2024-02-11

    c language. , to obtain pseudo-random numbers.

    The srand() and rand() functions are mainly used.

    The rand() function returns a pseudorandom number, but this is done mathematically.

    The calculated random number distribution is too concentrated, so the srand() function should be used to set the seed that generates the random number, and the current time is generally used as the seed, so that the pseudo-random number with a relatively uniform distribution can be obtained.

    rand(), srand() functions are located at.

    In the file, the time() function to get the time is located in the file. The random number test is as follows:

    include

    include

    include

    voidmain()

    intresults[10];*Used to save the result of random number generation* inti=0;

    srand((int)time(0));*set seed* for(i=0; i<10;i++)

    results[i]=0;

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

    results[rand()%10])+ * take a random number 10,000 times and use the remainder operator.

    So that the final random number obtained is less than 10*

    for(i=0;i<1

    0;i++)

    printf("dd

    n",i,results[i]);*Outputs the number of occurrences of a random number between 0-9*

    After many run tests, the random number produced is relatively uniform.

  2. Anonymous users2024-02-10

    The rand() function will return a pseudo-random number, but this is calculated by a mathematical formula, and the distribution of the obtained random number is too concentrated, so the srand() function should be used to set the seed that generates the random number, and the current time is generally used as the seed, so that a pseudo-random number with a relatively uniform distribution can be obtained.

    The rand(), srand() functions are located in the file, and the time() function to get the time is located in the file. rand()%9+1;

    rand()%9

    Generate a random number of 0 8;

    rand()%9+1 Random number of 1 9;

  3. Anonymous users2024-02-09

    1. First of all, you need to define a max minimum variable.

    2. Then give the value of the first address to the minimum value.

    3. Next, you can start to make a convenient search.

    4. If the number is greater than the maximum value, it can be automatically replaced.

    5. Then you can output the minimum value.

    6. Then after running, you can see the minimum value displayed on the screen.

  4. Anonymous users2024-02-08

    1. First of all, you need to define a max minimum variable.

    2. Then give the value of the first address to the minimum value.

    3. Next, you can start to make a convenient search.

    4. If the number is greater than the maximum value, it can be automatically replaced.

    5. Then you can output the minimum value.

    6. Then after running, you can see the minimum value displayed on the screen.

  5. Anonymous users2024-02-07

    main()

    for(i=i;iprintf("The smallest of the n numbers is: %d",shuzu[k]);

    printf("The smallest number is the %d number",k);}

  6. Anonymous users2024-02-06

    If you say how many you want to count, if you do, it's simple.

    #include

    int main()

    for(d=0;d<=n;d++)

    return 0;}

  7. Anonymous users2024-02-05

    Idea: 2-digit integer, divisible.

    2 gets a number of ten digits, and dividing by 10 gives a single digit. Cycle through the integer of 1 100 and judge the sum of its ten digits and single digits.

    If the filtered data is not considered for storage, the printout is judged directly in the loop.

    If you want to store the data, print it in a loop, and define the array storage.

    Below ** (the integers that are satisfied by the filter are stored in the array):

    #include <

    int main()

    int i,num[100],g,s;

    for(i=1;i<=100;i++)

    num[i-1]=i;

    g=i%10;Bit.

    s=i/10;Ten bits.

    if(g+s==3)

    printf("The addition of the digits to the digits %d is equal to 3, skip! ",i),num[i-1]=-1;

    printf("All remaining numbers are:");

    i=100;

    while(i>0)

    if(num[100-i]!=-1)

    printf("%d ",num[100-i]);

    i--;return 0;

  8. Anonymous users2024-02-04

    There's nothing wrong with the program, but it just doesn't indicate its maximum position. It should be:

Related questions
10 answers2024-06-14

You start by writing a function to find a sequence.

Then use for or while to call the !! >>>More

13 answers2024-06-14

The fflush function can be used to refresh a stream, which can be used to prevent the memory address from being full, when the stream is pointed to the user's standard input (stdin), it can clear the content in the current buffer, and the input return will also be clear, for example, using fflush(stdin) after scanf() is to automatically clear all the data in the input stream buffer when the input buffer (memory) is full, in fact, the memory is so large now, the data entered each time is only a few bytes, It is almost not used, and the most used place is in embedded development, because there is generally only a few tens of K space on each solidified chip, so the space is very important, and it will be used at this time.

5 answers2024-06-14

Arithmetic Operator:

Addition operators. >>>More

20 answers2024-06-14

That's it, this belongs to the parameter transfer between forms, there are many ways! >>>More

8 answers2024-06-14

I want to ask, have you written it now?