Home > front end >  Generate 1000 pairs of random numbers and tabulate each pair like 00, 01,02, ….., 99 in C
Generate 1000 pairs of random numbers and tabulate each pair like 00, 01,02, ….., 99 in C

Time:10-15

I want to generate 10,000 pairs of numbers between 0 and 9. like 00,01,02,03....99. I tried with the following function but it did not produce the desired results.

for(int i=0; i<1000; i  )
{
    rand_num = (int)(100.0*rand()/(RAND_MAX  1.0));
    printf (" %d ", rand_num);
}

can anyone help me to solve this?

CodePudding user response:

If you want zero prefix just tell printf to do that

for(int i=0; i<1000; i  )
{
    rand_num = (int)(100.0*rand()/(RAND_MAX  1.0));
    printf (" d ", rand_num);
}

Demo

Read the documentation on the format specifier

CodePudding user response:


for(int i=0; i<10000; i  )
{
    char d1 = '0'   rand();
    char d2 = '0'   rand();
    printf("%c%c ", d1, d2);
}
printf("\n");

  •  Tags:  
  • c
  • Related