answer.
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]
2 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]2 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]2 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
Justify the statement "The same job title can have different job roles and different qualification criteria in different organiz
Lana71 [14]

Answer:

Below is an executive summary of this particular issue.

Explanation:

  • Each organization has differential requirements and preferences. This same employment opportunities rely heavily on either the structure of the company and indeed the amount of equipment that it possesses.
  • Hence, whenever they recruit an individual on a specific job, their work description can differ based on the organization's needs including growth.
4 0
2 years ago
a. a large central network that connects other networks in a distance spanning exactly 5 miles. b. a group of personal computers
ki77a [65]

Complete Question:

A local area network is:

Answer:

b. a group of personal computers or terminals located in the same general area and connected by a common cable (communication circuit) so they can exchange information such as a set of rooms, a single building, or a set of well-connected buildings.

Explanation:

A local area network (LAN) refers to a group of personal computers (PCs) or terminals that are located within the same general area and connected by a common network cable (communication circuit), so that they can exchange information from one node of the network to another. A local area network (LAN) is typically used in small or limited areas such as a set of rooms, a single building, school, hospital, or a set of well-connected buildings.

Generally, some of the network devices or equipments used in a local area network (LAN) are an access point, personal computers, a switch, a router, printer, etc.

4 0
1 year ago
(Displaying a Sentence with Its Words Reversed) Write an application that inputs a line of text, tokenizes the line with String
Serjik [45]

Answer:

I am writing a JAVA and Python program. Let me know if you want the program in some other programming language.

import java.util.Scanner; // class for taking input from user

public class Reverse{ //class to reverse a sentence

public static void main(String[] args) { //start of main() function body

Scanner input = new Scanner(System.in); //create a Scanner class object

   System.out.print("Enter a sentence: "); //prompts user to enter a sentence

   String sentence = input.nextLine(); // scans and reads input sentence

   String[] tokens = sentence.split(" "); // split the sentence into tokens using split() method and a space as delimiter

   for (int i = tokens.length - 1; i >= 0; i--) { //loop that iterates through the tokens of the sentence in reverse order

       System.out.println(tokens[i]); } } } // print the sentence tokens in reverse order

Explanation:

In JAVA program the user is asked to input a sentence. The sentence is then broken into tokens using split() method. split method returns an array of strings after splitting or breaking the sentence based on the delimiter. Here the delimiter used is space characters. So split() method splits the sentence into tokens based on the space as delimiter to separate the words in the sentence. Next the for loop is used to iterate through the tokens as following:

Suppose the input sentence is "How are you"

After split() method it becomes:

How

are

you

Next the loop has a variable i which initialized to the tokens.length-1. This loop will continue to execute till the value of i remains greater than or equals to 0.

for (int i = tokens.length - 1; i >= 0; i--)

The length of first token i.e you is 3 so the loop executes and prints the word you.

Then at next iteration the value of i is decremented by 1 and now it points at the token are and prints the word are

Next iteration the value of i is again decremented by i and it prints the word How.

This can be achieved in Python as:

def reverse(sentence):

   rev_tokens = ' '.join(reversed(sentence.split(' ')))

   return rev_tokens

   

line = input("enter a sentence: ")

print((reverse(line)))

The method reverse takes a sentence as parameter. Then rev_tokens = ' '.join(reversed(sentence.split(' ')))  statement first splits the sentence into array of words/tokens using space as a delimiter. Next reversed() method returns the reversed sentence.  Next the join() method join the reversed words of the sentence using a space separator ' '.join(). If you want to represent the reversed tokens each in a separate line then change the above statement as follows:

rev_tokens = '\n'.join(reversed(sentence.split(' ')))  

Here the join method joins the reversed words separating them with a new line.

Simply input a line of text and call this reverse() method by passing the input line to it.

4 0
1 year ago
Write a function that implements another stack function, peek. Peek returns the value of the first element on the stack without
devlian [24]

Answer:

See explaination

Explanation:

StackExample.java

public class StackExample<T> {

private final static int DEFAULT_CAPACITY = 100;

private int top;

private T[] stack = (T[])(new Object[DEFAULT_CAPACITY]);

/**

* Returns a reference to the element at the top of this stack.

* The element is not removed from the stack.

* atreturn element on top of stack

* atthrows EmptyCollectionException if stack is empty

*/

public T peek() throws EmptyCollectionException

{

if (isEmpty())

throw new EmptyCollectionException("stack");

return stack[top-1];

}

/**

* Returns true if this stack is empty and false otherwise.

* atreturn true if this stack is empty

*/

public boolean isEmpty()

{

return top < 0;

}

}

//please replace "at" with the at symbol

Note:

peek() method will always pick the first element from stack. While calling peek() method when stack is empty then it will throw stack underflow error. Since peek() method will always look for first element ffrom stack there is no chance for overflow of stack. So overflow error checking is not required. In above program we handled underflow error in peek() method by checking whether stack is an empty or not.

3 0
2 years ago
Which of the following is an absolute cell reference
rodikova [14]

Answer:

The content of the cell is called an absolute cell reference.

Explanation:

Ms-excel can hold a value or string or number or formulas in each cell.  

The end-user can input the values to a cell and do any calculation by using inbuilt formulas and do the necessary calculation and get the output in the required cell  

When end-user try to copy and paste the data to another cell he or she can use paste special option where he or she can select values, by selecting values to end-user is just copying the data not formula this is called absolute reference of the cell

By using paste special end users copy the image or Unicode also.

This process is called an absolute cell reference

6 0
1 year ago
Other questions:
  • What is the major function of the network access layer?
    5·1 answer
  • When seeking information on the internet about a variety of subjects the most useful place to look would be?
    13·2 answers
  • Assuming that the valid cost should be between 100 and 200, does the following code snippet test this condition correctly?
    10·1 answer
  • Write multiple if statements: If carYear is before 1968, print "Probably has few safety features." (without quotes). If after 19
    6·1 answer
  • Write a client program that writes a struct with a privateFIFO name (call it FIFO_XXXX, where XXXX is the pid that you got from
    11·1 answer
  • E xercise 17.2.4: The following is a sequence of undo-log records written by two transactions T and U: &lt; START T&gt;; ; &lt;
    15·1 answer
  • Amanda a recently moved into a new home. Everyone has their own tablet, and wants to connect to the same network, no matter wher
    12·1 answer
  • The Boffo Balloon Company makes helium balloons. Large balloons cost $13.00 a dozen, medium-sized balloons cost $11.00 a dozen,
    13·1 answer
  • Which is the correct notation to specify the following inheritance?
    8·1 answer
  • An online retailer is looking to implement an enterprise platform. Which component of the enterprise platform will help the comp
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!