Question

Write the code in C with all the right output please.

Problem: In this assignment you will analyze a data set of 10,000 randomly generated integers. From this data set you will di

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey here is answer to your question.

In case of any doubt comment below. Please UPVOTE if you Liked the answer.

#include <stdio.h>

int isPrime(int n)
{
if (n <= 1)
return 0;
for (int i = 2; i < n; i++)
if (n % i == 0)
return 0;
  
return 1;
}

int main(int argc, char const *argv[])
{  
   int seed;
   printf("Enter seed value -> ");
   scanf("%d",&seed);
   srand(seed);
  
   int range = rand()%seed;

   int array[10000];
   double sum = 0;
  
   for (int i = 0; i < 10000; ++i)
   {
       array[i] = (rand() % (range)) + 1;
       sum = sum + array[i];
   }

   double avarage = (sum/10000);

   int counter =0;

   for (int i = 0; i < 10000; ++i)
   {
       if (array[i] >= avarage)
           if (isPrime(array[i]))
               counter++;
   }

   printf("Range for the problem is [1 - %d]\n",range);
   printf("Number of primes larger than dataset avarage [%.1f] : %d \n",avarage,counter);

   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write the code in C with all the right output please. Problem: In this assignment you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C programming. Write the code described in the picture with given 2 example executions of the...

    C programming. Write the code described in the picture with given 2 example executions of the code, and they must match. AND YOU CANT USE if statements! Problem: Allow the user to enter a positive integer value to represent the seed value for the random number generator. Next, generate a random integer that represents a possible number of points that a student may earn in a given class (0 to a maximum of 1000 possible points). Calculate the corresponding letter...

  • Please answer this questions in language C and make sure all executions work. Problem: Given an...

    Please answer this questions in language C and make sure all executions work. Problem: Given an integer as input determine if the digits in a second integer appear in the first integer in the same order (left to right, but not necessarily consecutive or at the same position). When the digits in the second integer (known as the target) do not appear in the first (known as the data) in the same order then identify the next integer value greater...

  • Write the Code in C program. Create a random password generator that contains a user-specified number...

    Write the Code in C program. Create a random password generator that contains a user-specified number of characters. Your program should prompt the user for the desired length of the password. Length of password: To create your password, use the random number generator in the stdlib.h C library. To generate random numbers, you will need the srand() and rand() functions. srand(seed) is used to "seed" the random number generator with the given integer, seed. Prompt the user for the seed...

  • Write a program in C to generate random numbers. The program recieves 4 items on activation...

    Write a program in C to generate random numbers. The program recieves 4 items on activation through argv: 1. Name of the data file 2. Number of items for program to generate 3. Range of numbers 4. Seed of the random number generator Example run: ./rand datafile.txt 20 1000 3127 Program must convert all numbers to ints using atoi(), must save all parameters into variables, opens the data file to write the random numbers into it, program loops to generate...

  • DESCRIPTION Implement a program in C++ that generates a specified number of random integers, records them...

    DESCRIPTION Implement a program in C++ that generates a specified number of random integers, records them in three arrays, then sorts the arrays with Insertion Sort, Merge Sort, and Quick Sort, respectively. Augment the three sorting algorithms with counters and report the number of characteristic operations each performs in sorting the (same) random values. INPUT The program reads from the terminal the number of random integers to generate, a seed value for the pseudo-random number generator, and a character that...

  • This assignment should be written in PYTHON programming language Please write python programs to answer the...

    This assignment should be written in PYTHON programming language Please write python programs to answer the following questions. Everything should be dynamically scraped from the live websites using the Beautiful Soup interface. Texas Dept of Criminal Justice (relevant url: http://www.tdcj.state.tx.us/death_row/dr_executions_by_year.html): Accept two integers as input. You can assume that these values represent a valid starting and ending year within the range of the years in the table. Process the html and find the total number of executions in Texas between...

  • For this assignment, write a program that will generate random numbers in the range of 50-100...

    For this assignment, write a program that will generate random numbers in the range of 50-100 and count how many fall into particular ranges. Processing: The program should first seed the random number generator. This is done one time in the program. Use srand(0). Next, generate and display a series of 10 random numbers between 50 and 100. There are several ways to ensure that a random number falls between 50 and 100. One possibility is to use the following...

  • C++ Guessing game. Create a project titled Lab4_Guess with a single file titled guess.cpp Program the...

    C++ Guessing game. Create a project titled Lab4_Guess with a single file titled guess.cpp Program the following game. The computer selects a random number between 1 and 100 and asks the user to guess the number. If the user guesses incorrectly, the computer advises to try larger or smaller number. The guessing repeats until the user guesses the number. The dialog should look as follows (user input is shown in bold): Guess a number between 1 and 100: 50 try...

  • Use linear congruential generator with seed value 31, a = 11, c = 17, m =...

    Use linear congruential generator with seed value 31, a = 11, c = 17, m = 100 and inverse transform technique to generate: 10 continuous uniform random variates on interval [1; 10];                                             [5] 10 exponential random variates with parameter λ = 3.                                                     [2] It is suspected that the generated random numbers (Ri) are autocorrelated, since an observer notices that every 4th number starting (but not counting) from the 1st number (i.e. i = 1) is larger...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT