Question

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] = numbers[i] + 1;
}
B. numbers[1]=2;

   numbers[2]=3;

   numbers[3]=4;

   numbers[4]=5;

   numbers[5]=6;
  C. numbers = {2,3,4,5,6};
  D. numbers = numbers + 1;

A. <stdlib.h>

B. <time.h>

C. <stdio.h>

D. <math.h>

0 0
Add a comment Improve this question Transcribed image text
Answer #1
1.
D. <math.h>


2.
A.
for (int i = 0; i < 5; i++) {
    numbers[i] = numbers[i] + 1;
}
B.
numbers[1]=2;
   numbers[2]=3;
   numbers[3]=4;
   numbers[4]=5;
   numbers[5]=6;
Add a comment
Know the answer?
Add Answer to:
1. Which of the following libraries must be included to run the following code: srand(time(0)); random...
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 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:...

  • Need help adjusting this code in C. I'm not sure this one part of the code...

    Need help adjusting this code in C. I'm not sure this one part of the code is correct, it needs to generate n random addresses between 0 and (2^32)-1. So I set it to "address = rand() % 232;" but I'm not sure if that is correct. Can you please fix thanks. #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { unsigned int address; unsigned int pg_num; unsigned int offset; unsigned int i; unsigned int n = 1000000; double time_taken;...

  • Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write...

    Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write a program that adds the following to the fixed code. • Add a function that will use the BubbleSort method to put the numbers in ascending order. – Send the function the array. – Send the function the size of the array. – The sorted array will be sent back through the parameter list, so the data type of the function will be void....

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

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

  • How would I be able to get a Merge Sort to run in this code? MY...

    How would I be able to get a Merge Sort to run in this code? MY CODE: #include <iostream> #include <fstream> #include <stdlib.h> #include <stdio.h> #include <time.h> using namespace std; class mergersorter { private:    float array[1000] ;    int n = 1000;    int i=0; public:    void fillArray()    {        for(i=1;i<=n;i++)        {            array[i-1]= ( rand() % ( 1000) )+1;        }    }    void arrayout ()    {   ...

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

  • Why i having this error using opengl C++ here part of code #include "glaux.h" #include "glut.h"...

    Why i having this error using opengl C++ here part of code #include "glaux.h" #include "glut.h" #include <stdio.h> #include <stdlib.h> #include <conio.h> #define _USE_MATH_DEFINES #include <math.h> #include <time.h> some coder here and etc bool isGood(Tpos a) { DataToCp(); int k=0,i,j,lt; Tpos temp; cp[a.y][a.x]='x'; if ((step(a.y,a.x)>3)||(step(a.y+1,a.x)>3)||(step(a.y-1,a.x)>3)||(step(a.y,a.x+1)>3)||(step(a.y,a.x-1)>3)) return false; for(j=1;j<=m;j++) for(i=1;i<=m;i++) if (cp[j][i]=='.') { if (k>0) return false; fill(j,i,&temp,&lt); k++; } return true; } void genMap() { int i,j; map.x=m+2; map.z=m+2; printf("Loading...\n"); srand( (unsigned)time( NULL ) ); for (j=0;j<map.z;j++) for (i=0;i<map.x;i++) {...

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