Computers and Technology, 05.05.2021 16:10 rousedem28381
Sort a vector Write a program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The first integer indicates how many numbers are in the list. Assume that the list will always contain less than 20 integers. Ex: If the input is:5 10 4 39 12 2the output is:2 4 10 12 39For coding simplicity, follow every output value by a space, including the last one. Your program must define and call the following function. When the SortVector function is complete, the vector passed in as the parameter should be sorted. void SortVector(vector & myVec) Hint: There are many ways to sort a vector. You are welcome to look up and use any existing algorithm. Some believe the simplest to code is bubble sort: https://en. wikipedia. org/wiki/Bubble_sort. But you are welcome to try others: https://en. wikipedia. org/wiki/Sorting_algorithm.
My code is:
#include
#include
using namespace std;
int main() {
int arr[20];
int count = 0, num, swap;
for(int i=0; i < 20; i++) {
arr[i] = 0;
}
for(int i=0; i<20; i++){
cin>>num;
if(num!=0){
arr[i] = num;
count++;
}
}
for(int i=0; i<20; i++) {
for(int j=i+1; j<20; j++) {
if(arr[i] != 0) {
if(arr[i]>arr[j]) {
swap = arr[i];
arr[i] = arr[j];
arr[j] = swap;
}
}
}
}
for(int i=0; i<20; i++) {
if(arr[i] != 0) {
cout<
}
}
return 0;
}
I used the given input (5 10 4 39 12 2) and expected the given output (2 4 5 10 12 39) but I am instead getting: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 5 10 12 39. I can't figure out why the 2 is repeating 15 times as it should only be there once.
Answers: 1
Computers and Technology, 22.06.2019 07:00
Robots with telescoping arms are sometimes used to perform tasks (e.g., welding or placing screws) where access may be difficult for other robotic types. during a test run, a robot arm is programmed to extend according to the relationship r = 3 + 0.5cos(4θ) and the arm rotates according to the relationship θ=−π4t2+πt , where r is in feet, θ is in radians, and t is in seconds. use a computer program to plot the path of tip a in x and y coordinates for 0 ≤ t ≤ 4s.
Answers: 2
Computers and Technology, 23.06.2019 00:00
How do we use the sumif formula (when dealing with different formats) ?
Answers: 1
Computers and Technology, 23.06.2019 03:30
Ihave a singular monitor that is a tv for my computer. recently, i took apart my computer and put it back together. when i put in the hdmi cord and booted the computer to see if it worked, the computer turned on fine but the screen was blue with "hdmi no signal." i've tried everything that doesn't require buying spare parts, any answer is appreciated!
Answers: 1
Computers and Technology, 24.06.2019 01:30
Hazel has just finished adding pictures to her holiday newsletter. she decides to crop an image. what is cropping an image?
Answers: 1
Sort a vector Write a program that gets a list of integers from input, and outputs the integers in a...
History, 26.07.2019 12:20
Social Studies, 26.07.2019 12:20
History, 26.07.2019 12:20
Social Studies, 26.07.2019 12:20
Mathematics, 26.07.2019 12:20
History, 26.07.2019 12:20
English, 26.07.2019 12:20
History, 26.07.2019 12:20