1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Romashka [77]
3 years ago
8

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

Computers and Technology
2 answers:
Dahasolnce [82]3 years ago
8 0

Answer:

#include

#include // Enables use of rand()

#include // Enables use of time()

int main(void) {

int seedVal = 0;

seedVal = 4;

srand(seedVal);

cout<< rand()%(int)(149-100+1) + 100;

cout<< rand()%(int)(149-100+1) + 100;

return 0;

}

Explanation:

The code segment starts at line 8 and ends at line 9.

That is:

cout<< rand()%(int)(149-100+1) + 100;

cout<< rand()%(int)(149-100+1) + 100;

The syntax for generating random values in C using rand function is

rand()%(int)(max - min + 1) + min

Or

min + rand()%(int)(max - min + 1).

It works both ways..

Where max and min represent the range of values needed (maximum and minimum)

The random statement can also be used in loops

rosijanka [135]3 years ago
6 0

Answer:

#include <stdlib.h>

#include <time.h>

#include<iostream.h>

int main(void) {

   int seedVal = 0;  

   seedVal = 4;

   srand(seedVal);

  /* Solution*/

  cout<<rand() % 149 + 100<<endl;

  cout<<rand() % 149 + 100<<endl;

  return 0;

}

Explanation:

We start with the required include statements to enable use of srand, rand and time functions. I have also added iostream library to use "cout" function.

After that, the seed is initialized using srand(). And then the two rand functions are called with ranges including and between 100 and 149, and printed out.

You might be interested in
Write a program that (a) generates a vector with 20 random integer elements with integers between -29 and 30, (b) replaces all t
Ghella [55]

Answer:

import random

randomlist = []

for i in range(0,20):

n = random.randint(-29,30)

if n < 0 :

n = 100

randomlist.append(n)

print(randomlist)

Explanation:

The random module is first imported as it takes care of random. Number generation.

An empty list called randomliay is created to hold the generated random integers.

Using a for loop, we specify the range of random numbers we want.

Inside the for loop ; we attach our generated random integer which will be in the range (-29 to 30) in a variable n

For each n value generated, if the value is less than 0( it is negative, since all the values are integers), replace the value with 100.

5 0
2 years ago
I need help with this work
lisabon 2012 [21]

Answer:

B. Balanced depending and the type of questions

5 0
2 years ago
The geographic coordinate system is used to represent any location on Earth as a combination of latitude and longitude values. T
Pachacha [2.7K]

Answer:

Here is the script:  

function dd = functionDMS(dd)  

prompt= 'Enter angle in DD form ';

dd = input(prompt)

while (~checknum(dd))

if ~checknum(dd)

error('Enter valid input ');

end

dd = input(prompt)

end  

degrees = int(dd)

minutes = int(dd - degrees)

seconds = ( dd - degrees - minutes / 60 ) * 3600  

print degrees

print minutes

print seconds

print dd

Explanation:

The script prompts the user to enter an angle in decimal degree (DD) form. Next it stores that input in dd. The while loop condition checks that input is in valid form. If the input is not valid then it displays the message: Enter valid input. If the input is valid then the program converts the input dd into degrees, minutes and seconds form. In order to compute degrees the whole number part of input value dd is used. In order to compute the minutes, the value of degrees is subtracted from value of dd. The other way is to multiply remaining decimal by 60 and then use whole number part of the answer as minutes. In order to compute seconds subtract dd , degrees and minutes values and divide the answer by 60 and multiply the entire result with 3600. At the end the values of degrees minutes and seconds are printed. In MATLAB there is also a function used to convert decimal degrees to degrees minutes and seconds representation. This function is degrees2dms.

Another method to convert dd into dms is:

data = "Enter value of dd"

dd = input(data)

degrees = fix(dd);

minutes = dd - degrees;

seconds = (dd-degrees-minutes/60) *3600;

8 0
3 years ago
The rules of a programming language constitute its__________________
kogti [31]
The rules of a programming language constitute its syntax.
7 0
1 year ago
What is the advantage of using the Publish Online option for sharing a calendar? It creates a web version that can be viewed by
kotykmax [81]

Answer:

its D. it allows a user outside an organization to view the calendar.

Explanation:

i just got it right on edge 2020.

7 0
2 years ago
Read 2 more answers
Other questions:
  • Create a stored procedure named prc_inv_amounts to update the INV_SUBTOTAL, INV_TAX, and INV_TOTAL. The procedure takes the invo
    8·1 answer
  • Discuss the differences between dimensionality reduction based on aggregation and dimensionality reduction based on techniques su
    13·1 answer
  • What is life all about?
    15·2 answers
  • Your organization wants to implement a 5-year rotation plan for all of its computing devices. What percentage of the computer fl
    10·2 answers
  • Someone please help fast! I’m taking the test rn and I don’t understand this!!!!!!
    15·1 answer
  • The following code processes a file containing five positive numbers. What will the variable $result contain after the code is e
    10·1 answer
  • What are the consequences of plagiarism?
    7·2 answers
  • 3.26 LAB: Leap Year A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate a
    15·2 answers
  • The Quick Search capability is found on which control?
    12·1 answer
  • What form of contacts can be shared in Outlook 2016?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!