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

101
133

Sample program:

#include
#include // Enables use of rand()
#include // Enables use of time()

int main(void) {
int seedVal = 0;

seedVal = 4;
srand(seedVal);



return 0;
}

Respuesta :

C Code:

#include <stdio.h>      // Enables use of printf

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

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

int main(void)

{

srand(time(0));  

int random1 = rand()% 50 + 100;

int random2 = rand()% 50 + 100;  

printf("%d\n", random1);

printf("%d\n", random2);

  return 0;

}

Output:

115

141

Explanation:

Each time program executes, srand() function generates new random numbers.

rand()%50 + 100 makes sure that number is 2 digit and within the range of 100 to 150.

Then we print the two random numbers where %d represents that we want to print an integer and \n represents new line  

Otras preguntas

RELAXING NOICE
Relax