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
jenyasd209 [6]
2 years ago
13

Write a program that gets a list of integers from input, and outputs non-negative integers in ascending order (lowest to highest

). Ex: If the input is: 10 -7 4 39 -6 12 2 the output is: 2 4 10 12 39
Computers and Technology
2 answers:
zhannawk [14.2K]2 years ago
7 0

Answer:

Following are the code to this question:

#include <iostream>//defining header file

using namespace std;

int main()//defining main method

{

   int a[]={10,-7,4,39,-6,12,2};//defining single deminition array and assign value

   int i,x,j,t; //defining integer variable

   cout<<"Before sorting value: ";  

   for(i=0;i<7;i++) //using loop to print value

   {

       cout<<a[i]<<" ";//print value

   }

   cout<<endl <<"After sorting value: ";

   for(i=0;i<7;i++)//defining loop to sort value

{  

 for(j=i+1;j<7;j++)//count array value

 {

  if(a[i]>a[j]) //defining condition to inter change value

  {

      //performing swapping

   t=a[i];  //integer variable t assign array value

   a[i]=a[j];//swapp value

   a[j]=t;//assign value in array

  }

 }

}

for(i=0;i<7;i++) //defining loop to print value

   {

       if(a[i]>=0) //defining condition to check positive value  

       {

       cout<<a[i]<<" ";//print value

       }

   }

   return 0;

}

Output:

Before sorting value: 10 -7 4 39 -6 12 2  

After sorting value: 2 4 10 12 39  

Explanation:

Following are the description to the above code:

  • In the above program code, Inside the main method, an array a[] is declared that assign some value, and another integer variable "i, j, x, and t" is declared, in which variable "i and j" are used in the loop, and "x, t" is used to sort value.
  • In the next step, three main for loop is declared, in which the first loop is used to print array value.
  • In the second loop, inside another loop is used that sorts array values.
  • In the last loop, a condition is defined, that check the positive value in the array and print its values.
yanalaym [24]2 years ago
3 0

Answer:

integers=[]

while True:

      number=int(input())

      if number<0:

       break

      integers.append(number)  

print("",min(integers))

print("",max(integers))

Explanation:

You might be interested in
A third-grade teacher at Potter Elementary School wants a program that allows a student to enter the amount of money a customer
mina [271]

Answer: IDK

Explanation: ummm I have no idea wut ur asking meh

6 0
2 years ago
Peter took a selfie in his room. He was a wearing a light blue shirt. But he failed to realize that that shirt would clash in co
Leto [7]

Answer:

A wand tool is to do that in an editing software.

7 0
2 years ago
Read 2 more answers
in a small office, there are 5 computers, a network printer, and a broadband connection to the internet. what devices are needed
Nataly [62]

Answer:

<em>Ethernet cables, Network Adapters, Modem, Routers, Switches.</em>

Explanation:

<em>The devices that are required in setting up a wired network for the 5 computer comprises of the following devices </em>

  • <em>Ethernet Cables</em>
  • <em>Network Adapters</em>
  • <em>Modem/Router</em>
  • <em>Network Switch</em>

<em>Ethernet cables: They are called network cables or RJ-45 cables used to in connecting two or more computers together. it has different categories called, the untwisted pair and twisted pair Ethernet, with a speed from 10-1000</em>

<em>Network Adapters : This adapters allows a computer device to connect and interface with a network computer</em>

<em>Modem/Routers : A router is a device that that sits in the  middle  between your local computers and modems. it takes receives information or gets information from the modem and delivers it to the computer</em>

<em>Network switch: it connects more than two computers together to a network and share data among themselves and other devices on the network</em>

6 0
2 years ago
A ____ partition contains the data necessary to restore a hard drive back to its state at the time the computer was purchased an
Oxana [17]
The answer is back up
8 0
2 years ago
Read 2 more answers
(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
2 years ago
Other questions:
  • Carlos owns a hardware store. He currently is not using any software to track what he has in the store. In one to two sentences,
    9·2 answers
  • A(n) ______close to a cover letter leads to more interviews because you are contacting the employer. a. passive b. lengthy c. ac
    11·2 answers
  • Which selections are possible for controlling the start time of audio playback? Check all that apply. Automatic Rewind when done
    10·1 answer
  • Survey Q, Non-scoring: What role are you playing in your team?
    5·2 answers
  • You are researching RAM for a computer you are building for a friend who will be using the system as a home office server for he
    14·1 answer
  • Which would be the most efficient way to store files on your computer?
    13·2 answers
  • While Angela is making modifications to Katie’s Word document, she would like to inform Katie of the reasoning for the change. W
    10·1 answer
  • What answer best explains why improper netiquette is considered dangerous? Individuals who violate user policies are often charg
    14·2 answers
  • All organizations need good quality cybersecurity to ensure _____. Select 4 options.
    12·2 answers
  • Import simplegui
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!