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
klio [65]
1 year ago
11

c g given an array, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero eleme

nts
Computers and Technology
1 answer:
o-na [289]1 year ago
6 0

The output for an array of elements [0,1,0,3,12] is  [1,3,12,0,0]

<h3>What is the function to get the desired output?</h3>
  • Let us consider an array of elements,

          Input = [0,1,0,3,12]

  • The function code is given by,

class Solution {

public:

   void moveZeroes(vector<int>& nums) {

       int count=0;

       for(int i=0;i<nums.size();i++)

       {

           if(nums[i]==0)

           {

               nums.erase(nums.begin()+i);

               ++count; //This is to count number of zeroes.

           }

       }

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

          nums . push_back(0);  //To input zero at the end of the vector count times.      

}

};

The output for an array of elements [0,1,0,3,12] is  [1,3,12,0,0] where all 0's are moved to the end,  while maintaining the relative order of the non-zero elements,

<h3>What is an array?</h3>
  • A collection of items that are either values or variables is referred to as an array in computer science.
  • Each element is identifiable by at least one array index or key.
  • Each element of an array is recorded such that a mathematical formula can be used to determine its position from its index tuple.
  • A linear array, often known as a one-dimensional array, is the simplest sort of data structure.

To learn more about array, refer:

brainly.com/question/19634243

#SPJ4

You might be interested in
To keep you from inadvertently moving controls as you work in the IDE, click the form or control, then click the _________ optio
Alenkinab [10]

Answer:

Lock controls

Explanation:

4 0
3 years ago
What is the meaning of Ram?​
masya89 [10]

Answer:

Random-Access Memory

Explanation:

used as a short-term memory for computers to place its data for easy access

5 0
1 year ago
Which of the following is an example of a complex formula?
myrzilka [38]

Answer:

=A1<=A14

Explanation:

complex formula in excel is which contain more than 1 mathematical operators . An order of mathematical operations are important to understand

there are different type of operators

  • Arithmetic operators
  • Comparison operators
  • Text operators
  • Operators reference

here Comparison operator is an example of complex formula . Comparison operator returns TRUE/FALSE it is use to compare two values

= Equal to

< Less than

> Greater than

>= Greater than or Equal to

<= Less than or Equal to

7 0
3 years ago
PLEASE HELP ASAP what is the main purpose of electronic speed controller ESC
iragen [17]

Answer:

<em><u>An electronic speed control (ESC) is an electronic circuit that controls and regulates the speed of an electric motor. It may also provide reversing of the motor and dynamic braking.</u></em>

Explanation:

<h3><em>I </em><em>hope</em><em> this</em><em> helps</em><em>!</em></h3>
4 0
2 years ago
Read 2 more answers
Write the class "Tests". Ensure that it stores a student’s first name, last name, all five test scores, the average of those 5 t
zhannawk [14.2K]

Answer:

The following assumption will be made for this assignment;

  • If average score is greater than 75, the letter grade is A
  • If average score is between 66 and 75, the letter grade is B
  • If average score is between 56 and 65, the letter grade is C
  • If average score is between 46 and 55, the letter grade is D
  • If average score is between 40 and 45, the letter grade is E
  • If average score is lesser than 40, the letter grade is F

The program is written in Java and it uses comments to explain difficult lines. The program is as follows

import java.util.*;

public class Tests

{

public static void main(String [] args)

{

 //Declare variables

 Scanner input = new Scanner(System.in);

 String firstname, lastname;

 //Prompt user for name

 System.out.print("Enter Lastname: ");

 lastname = input.next();

 System.out.print("Enter Firstname: ");

 firstname = input.next();

 char grade;

 //Declare Array

 int[] Scores = new int[5];

 //Initialize total scores to 0

 int total = 0;  

  //Decalare Average

  double   average;

 //Prompt user for scores

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

 {

  System.out.print("Enter Score "+(i+1)+": ");

  Scores[i] = input.nextInt();

  //Calculate Total Scores

  total+=Scores[i];

 }

 //Calculate Average

 average = total/5.0;

 //Get Letter Grade

 if(average>75)

 {

 grade = 'A';

 }

 else if(average>65)

 {

 grade = 'B';

 }

 else if(average>55)

 {

 grade = 'C';

 }

 else if(average>45)

 {

 grade = 'D';

 }

 else if(average>40)

 {

 grade = 'E';

 }

 else

 {

 grade = 'F';

 }

 //Print Student Results

 System.out.print("Fullname: "+lastname+", "+firstname);

 System.out.print('\n');

 System.out.print("Total Scores: "+total);

 System.out.print('\n');

 System.out.print("Average Scores: "+average);

 System.out.print('\n');

 System.out.print("Grade: "+grade);

}

}

See Attachment for .java file

Download java
7 0
3 years ago
Other questions:
  • What car dealership websites did you use to conduct your research?​
    8·1 answer
  • A Pool charges $4 each visit,or you can buy a membership. Write and solve an inequality to find how many times a person should u
    5·1 answer
  • How to write a program converting RGB to CMYK in python
    6·1 answer
  • The command to delete all the files that have filenames that starts with letter c or c and ends with a letter z or z is
    15·1 answer
  • Assume you have a int variable n that has already been declared and initialized. Its value is the number of integers that need t
    13·1 answer
  • . List four different ways automation can be used in testing?
    11·1 answer
  • What is the cell reference for row 22 and column B? __________<br><br> In excel
    5·1 answer
  • WILL GIVE BRAINLIEST ANSWER!!!<br><br> How do you manage your screen time?
    8·2 answers
  • Select the best answer to the following question.
    5·1 answer
  • Describe the plot of the Matrix
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!