Question

C PROGRAM ONLY!!! 1). Type a statement using srand() to seed random number generation using variable...

C PROGRAM ONLY!!!

1). Type a statement using srand() to seed random number generation using variable seedVal. Then type two statements using rand() to print two random integers between (and including) 0 and 9. End with a newline. Ex: 5 7 Note: For this activity, using one statement may yield different output (due to the compiler calling rand() in a different order). Use two statements for this activity. Also, after calling srand() once, do not call srand() again. (Notes)

GIVEN:

#include <stdio.h>
#include <stdlib.h> // Enables use of rand()
#include <time.h> // Enables use of time()

int main(void) {
int seedVal = 0;

/* Your solution goes here */

return 0;
}

2). Type two statements that use rand() to print 2 random integers between (and including) 100 and 149. End with a newline. Ex:

101
133

Note: For this activity, using one statement may yield different output (due to the compiler calling rand() in a different order). Use two statements for this activity. Also, srand() has already been called; do not call srand() again.

GIVEN:

#include <stdio.h>
#include <stdlib.h> // Enables use of rand()
#include <time.h> // Enables use of time()

int main(void) {
int seedVal = 0;

seedVal = 4;
srand(seedVal);

/* Your solution goes here */

return 0;
}

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

C Program:

(1)

#include <stdio.h>
#include <stdlib.h>   // Enables use of rand()
#include <time.h>     // Enables use of time()

int main(void) {
   int seedVal = 0;

   /* Your solution goes here */

    //Seeding random generator
    srand(seedVal);

    //Printing first random number
    printf(" %d ", (rand() % 10));

    //Printing second random number
    printf(" %d \n", (rand() % 10));

   return 0;
}

Sample Run:

______________________________________________________________________________________________

(2)

#include <stdio.h>
#include <stdlib.h>   // Enables use of rand()
#include <time.h>     // Enables use of time()

int main(void) {
   int seedVal = 0;

   seedVal = 4;
   srand(seedVal);

   /* Your solution goes here */

    //Random numbers in the range [100, 149]

   //Printing first random number
    printf(" %d \n", (100 + rand() % (149 + 1 - 100)));

    //Printing second random number
    printf(" %d \n", (100 + rand() % (149 + 1 - 100)));

   return 0;
}

Sample Output:

Add a comment
Know the answer?
Add Answer to:
C PROGRAM ONLY!!! 1). Type a statement using srand() to seed random number generation using variable...
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
  • Lines 10& 11 are wrong Lines 12 & 13 are wrong CHALLENGE 2.19.2 rand function: Seed...

    Lines 10& 11 are wrong Lines 12 & 13 are wrong CHALLENGE 2.19.2 rand function: Seed and then get random numbers Type a statement using srand0 to seed random number generation using variable seedVal. Then type two statements using rand to print two random integers between (and including) 0 and 9. End with a newline. Ex Note. For this activity, using one statement may yield different output (due to the compiler calling rand0 in a different order). Use two statements...

  • intro to c Caras → XCO D Question 6 10 pts The program below is intended...

    intro to c Caras → XCO D Question 6 10 pts The program below is intended to traverse a random array, calculate an average and print a forward slash usings. For example, if the array is Initialized with values 4, 5, 4, and 3, the average would be 4, and we would print the following Type the statements or constructs you would use in each of the marked sections to complete the program #include <stdio.h> #include <stdlib.h> #include <time.h> int...

  • 9. The purpose of the following program is to generate 10 random integers, store them in...

    9. The purpose of the following program is to generate 10 random integers, store them in an array, and then store in the freq frequency array, the number of occurrences of each number from 0 to 9. Can you find any errors in the program? If yes, correct them. #include <stdio.h> #include <stdlib.h> #include <time.h> #define SIZE 10 int main(void) int i, num, arr[SIZE], freq[SIZE]; srand (time (NULL)); arr[1] rand(); SIZE; for(i i 〈 i++) num arr[i]; freq[num]++; printf("InNumber occurrences...

  • My C program is supposed to make a random key the same length of clear_text string...

    My C program is supposed to make a random key the same length of clear_text string and then use the random key to encrypt clear_text, but I can’t get it to work. A wΝΗ 1 #include <stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 char* make_rand_key(int length, char* key); 5 void encrypt(); 7- int main() { 8 encrypt(); 9 } 10 char* make_rand_key(int length, char* key){ int range=78; int max=48; char c='a'; int i; 'srand(time(NULL)); for(i=0;i<length;i++){ C=rand()%range_max; key[i]=c; key[i]='\0'; return key; 23...

  • Use only C Program for this problem. Must start with given codes and end with given...

    Use only C Program for this problem. Must start with given codes and end with given code. CHALLENGE ACTIVITY 9.4.3: Input parsing: Reading multiple items. Complete scanf( to read two comma-separated integers from stdin. Assign userlnt1 and userInt2 with the user input. Ex: "Enter two integers separated by a comma: 3,5", program outputs: 3 + 5 = 8 1 #include <stdio.h> HNM 1 test passed int main(void) { int user Int1; int user Int2; All tests passed 000 printf("Enter two...

  • Your task: 1. Study Slides 24 -28 of “FunctionCalling.pptx” 2. Answer the following question in a...

    Your task: 1. Study Slides 24 -28 of “FunctionCalling.pptx” 2. Answer the following question in a separate file, called “Assignment#4.pdf”: • Show all the possible outcomes of the experiment (rolling the dice) using a 2-D table. (see Slides 26, 27) • What are the events (possible sums) such as 2, 3, … (See Slide 26, 27). Example: Number Distribution so Generating numbers that conform a given distribution so Create an array to store all possible outcomes. int twodices[OUTCOME ]={2,3,4,5,6,7, 3,4,5,6,7,8,...

  • 4. Write a program that generates one hundred random integers between 0 and 9 and displays...

    4. Write a program that generates one hundred random integers between 0 and 9 and displays the count for each number. (Hint: Use rand()%10 to generate a random integer between 0 and 9. Use an array of ten integers, say counts, to store the counts for the number of 0’s, 1’s,…..,9’s.) this program kinda works but i cant figure out why its making more than 100 random numbers ls) [*] test2.cpp test3.cpp #include<stdio.h> #include<stdlib.h> int main() 4 { int a[14],is...

  • I need the programming to be in language C. I am using a program called Zybook...

    I need the programming to be in language C. I am using a program called Zybook Prompt: Write a statement that outputs variable numObjects. End with a newline. Given: #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); return 0; } What I did so far. I am not sure if its right tho? #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); printf(" num Objects is "); printf("%d\n", userAge); return 0; }

  • Merge Sort: Time Complexity: O(n log(n)) #include "stdafx.h" #include <iostream> #include <time.h> #include <stdlib.h> using namespace...

    Merge Sort: Time Complexity: O(n log(n)) #include "stdafx.h" #include <iostream> #include <time.h> #include <stdlib.h> using namespace std; void combine(int *a, int low, int high, int mid) {        int i, j, k, c[100000];        i = low;        k = low;        j = mid + 1;        while (i <= mid && j <= high)        {               if (a[i] < a[j])               {                      c[k] = a[i];                      k++;                      i++;               }               else               {                     ...

  • I need Help PLZ. I can't solving this in C program Given is a C program count_primes.c, which is an array Generates 10000 six-digit random numbers and then determines the number of primes in that...

    I need Help PLZ. I can't solving this in C program Given is a C program count_primes.c, which is an array Generates 10000 six-digit random numbers and then determines the number of primes in that array. It also measures the time that elapses during the calculation and returns it to the console along with the number of primes it finds. (a) Rewrite the program so that N threads are used to count the primes in the array. Each thread is...

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