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
Tamiku [17]
3 years ago
9

In this exercise, you will write some code that reads n unique (no duplicates!) non-negative integers, each one less than fifty

(50). Your code will print them in sorted order without using any nested loops-- potentially very efficient! We'll walk you through this: First, assume you are given an int variable n, that contains the number of integers to read from standard input. Also assume you are given an array, named wasReadIn, of fifty (50) bool elements and initialize all the elements to false. Third, read in the n integers from the input, and each time you read an integer, use it as an index into the bool array, and assign that element to be true-- thus "marking" in the array which numbers have been read. Lastly the "punchline": write a loop that traverses the bool array: every time it finds an element that is true it prints out the element's INDEX -- which was one of the integers read in. Place all the numbers on a single line, separated by a single spaces. Note: this technique is not limited to 50 elements-- it works just as well for larger values. Thus, for example you could have an array of 1,000,000 elements (that's right-- one million!) and use it to sort numbers up to 1,000,000 in value!
Computers and Technology
1 answer:
Rashid [163]3 years ago
5 0

Answer:

// This program is written in C++

// It sorts array of n distinct elements in ascending order

// Comments are used for explanatory purpose

// Program starts here

#include <iostream>

using namespace std;

// Declare a maximum of 50

#define MAX 50

int main()

{

//The next line declares the array of 50 maximum integers

int Readln[MAX];

// The next line declares length of array

int n;

int temp;

// Prompt user to enter length of array

cout<<"Length of Array: ";

cin>>n;

//Check if length falls within range of 2 to MAX

while (n<2 || n>MAX)

{

cout<<"Array must have at least 2 elements and can't be more than "<<MAX<<endl;

}

// The next line declares an input element

int digit;

// The next loop statement accepts distinct array elements

for(int i=0; i<len;i++)

{

cout<<"Enter element ["<<i+1<<"] ";

cin>>digit;

// Check if digit is non-negative and less than 50; repeat until element is within range

while (digit<0 || n>49)

{

cout<<"Acceptable range is 0 to 49";

cin>>digit;

}

Readln[i] = digit;

}

//The next iteration sorts the array

for(i=0;i<n;i++)

{

for(int j=i+1;j<n;j++)

{

if(Readln[i]>Readln[j])

{

// Swap Elements

temp =Readln[i];

Readln[i]=arr[j];

Readln[j]=temp;

}

}

}

// The next line prints array elements

for(i=0;i<n;i++)

cout<<Readln[i]<<"\t";

cout<<endl;

return 0;

}

// End of program

You might be interested in
You are adding a new 500 GB hard drive to your computer. The hard drive must be formatted with a file system to organize files i
AURORKA [14]
<h2>Answer:</h2><h3>NTFS is recommended according to given scenario.</h3>

<h2>Explanation:</h2>

Following are some point that help you understand the term NTFS:

  • NTFS is abbreviation of New Technology File System.
  • It is a file system that is commonly used in Windows Operating system now a days. Today's computers use NTFS widely.
  • Files are stored and retrieved on hard drive by means of the NTFS.
  • NTFS is somehow an advanced version o FAT(File allocation Table) and HPFS.
  • NTFS is adopted as it is extendtable as well as secure.

<h3>I hope it will help you!</h3>
3 0
4 years ago
An IT department submits a purchase order to buy a new computer from a vendor. "Purchase orders" are documents issued by buyers
Umnica [9.8K]

Answer:

Procurement

Explanation:

Characteristics hardware lifecycle:

  • Procurement- Acquiring new IT hardware assets involves evaluating vendors, purchase orders, receiving, and device labeling.
  • Deployment - Hardware configuration and installment, placing hardware and software assets into production environments.
  • Maintenance & Support - Management of assets include scheduling scans and getting audit history.
  • Upgrade - Before you retire your IT hardware assets, you’ll reach a processing plateau that can be restored with hardware upgrades.
3 0
4 years ago
If you want to distribute a formatted Microsoft word document to people who don't have word save it as a __file
Helga [31]
If you want them only to read it and not change it send as a .pdf else I would send as a .txt file. Hope that helps
5 0
3 years ago
What does Stand for in web design
myrzilka [38]

Answer:

g

Explanation:

h

7 0
3 years ago
The scope of a variable declared outside of any function is:
Marta_Voda [28]

Answer:

a) Global

Explanation:

The scope of a variable declared outside of any function is Global.

Let us consider an example:

int g;

int  add(int a,int b){

   return a+b;

}

int  subtract(int a,int b){

   return a-b;

}

Here the variable g is defined outside any function and is accessible anywhere within the program. This is a global variable.

Variables defined within each function - a,b on the other hand have a local scope are are visible only within their respective function bodies.

5 0
4 years ago
Other questions:
  • Which is the output of the formula =AND(12&gt;6;6&gt;3;3&gt;9)
    6·1 answer
  • In microsoft windows when a window is minimized what happens to that window
    9·1 answer
  • 12. Noodle Tools is a website that
    8·1 answer
  • How long did it take Linkedln to reach 1 million users?
    5·2 answers
  • Grbn kmjnhbgvfcdxswikmjnthbrvgt
    5·2 answers
  • Please refer to the MIPS solution in the question above. How many total instructions are executed during the running of this cod
    10·2 answers
  • What is the data and information with example? ​
    9·1 answer
  • Why can't this app have people ask riddles.
    8·1 answer
  • The higher the ____________________, the faster the ____________________.
    5·1 answer
  • A _____ is an Access database object that allows you to arrange the fields of a record in any layout so you can enter, edit, and
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!