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...

  • 2.13.2: Get random numbers. JAVA Type two statements using nextInt() to print two random integers between...

    2.13.2: Get random numbers. JAVA Type two statements using nextInt() 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 interpreter calling randGen.nextInt() in a different order). Use two statements for this: import java.util.Scanner; import java.util.Random; public class DiceRoll { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); Random randGen = new Random();...

  • 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...

  • 1. Which of the following libraries must be included to run the following code: srand(time(0)); random...

    1. Which of the following libraries must be included to run the following code: srand(time(0)); random = rand(); (select ALL that are required and do not select any that are NOT required). 2. Given the code: int numbers[5] = {1,2,3,4,5}; Select all from the following answers which can be used (in C) to change the values in the numbers array to 2, 3, 4, 5 and 6. A. for (int i = 0; i < 5; i++) { numbers[i] =...

  • 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...

  • Can someone help me get this C program to work? I am trying to get a...

    Can someone help me get this C program to work? I am trying to get a 2d array to work correctly. /* Deals a random hand of cards */ #include <stdio.h> #include <stdlib.h> #include <time.h> #define TRUE 1 #define FALSE 0 #define BOOL int #define NUM_SUITS 4 #define NUM_RANKS 13 int main() { BOOL in_hand[NUM_SUITS][NUM_RANKS] = {FALSE}; int num_cards = 13, rank, suit; const char rank_code[ 13 ][ 10 ] = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}; const char suit_code[ 4 ] [ 10 ]...

  • 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...

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