I am writing in C andI need the result to be like the inputs

I am writing in C andI need the result to be like the inputs below for this project, but I get a different result, can I get help?

1. Name this program random. c-This program looks at random numbers integers in the range of 0 through 99. The program prompts for the number of values to generate in the range of 0 to 99, generates that many random numbers, and determines how many different (unique numbers were actually generated. Running on the cs-intro server gives you the following results (three different executions of the program are shown) How many random values to generate 1 1 random numbers generated 1 out of 100 possible values How many random values to generate 10 10 random numbers generated 9 out of 100 possible values How many random values to generate 250 250 random numbers generated 93 out of 100 possible values Hints: Recall that the statement rand 100 will generate a random number in the range of 0 to 99 Use an array of 100 elements to store the number of times you\'ve seen the values 0, 1, 2, 99 Initialize this array to zeroes, and also use srand (0) to seed your random number generator. Your program should read in a number, and then generate that many random numbers. For each random number generated, increment that location in the array by one. After generating that many random numbers, count how many elements in the array are non-zero (which means that random number was generated at least once).

Solution

random.c

#include <stdio.h>
#include <math.h>
int main()
{
   int n;
   printf(\"How many random numbers you want to generate?\ \");
   scanf(\"%d\", &n);
   int arr[100];
   int i = 0;
   while(i<100)
   {
       arr[i]= 0;
       i++;
   }
   i = 0;

   while(i<n)
   {
       int r = rand()%100;
       arr[r]=1;
       i++;
   }
   i = 0;
   int count = 0;
   while(i<100)
   {
       if(arr[i] == 1)
       {
           count++;
   }
       i++;
   }
   printf(\"%d random numbers generated %d out off 100 possible values!\ \",n,count);
   return 0;
}

sample output:

How many random numbers you want to generate?
250
250 random numbers generated 93 out off 100 possible values!
akash@akash-SVE15116ENB:~/Desktop/chegg/random c$ ./a.out
How many random numbers you want to generate?
10
10 random numbers generated 9 out off 100 possible values!
akash@akash-SVE15116ENB:~/Desktop/chegg/random c$ ./a.out
How many random numbers you want to generate?
1
1 random numbers generated 1 out off 100 possible values!
akash@akash-SVE15116ENB:~/Desktop/chegg/random c$ ./a.out
How many random numbers you want to generate?
20
20 random numbers generated 18 out off 100 possible values!
akash@akash-SVE15116ENB:~/Desktop/chegg/random c$ ./a.out
How many random numbers you want to generate?
50
50 random numbers generated 38 out off 100 possible values!

I am writing in C andI need the result to be like the inputs below for this project, but I get a different result, can I get help? 1. Name this program random.
I am writing in C andI need the result to be like the inputs below for this project, but I get a different result, can I get help? 1. Name this program random.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site