// the program attempts to sort three integers // in increasing order, it is incomplete // Mikhail Nesterenko // 9/3/2009 #include <iostream> using std::cin; using std::cout; using std::endl; int main(){ // inputs the numbers cout << "Enter three numbers: "; int x, y, z; cin >> x >> y >> z; int tmp; // orders x and y if (x > y){ tmp = x; x = y; y = tmp; } // orders y and z if (y > z){ tmp = y; y = z; z = tmp; } // outputs the sorted numbers cout << "The sorted numbers are: "; cout << x << " " << y << " " << z << endl; }
Can anyone help complete?
Completed the code:
#include <iostream>
using namespace std;
int main(){
// inputs the numbers
cout << "Enter three numbers: ";
int x, y, z;
cin >> x >> y >> z;
int tmp;
// orders x and y
if (x > z){
tmp = x;
x = z;
z = tmp;
}
// orders y and z
if (x > y){
tmp = y;
x = y;
y = tmp;
}
//Now the smallest element is the first one. Just check the 2-nd
and 3-rd
if (y > z){
tmp = y;
y = z;
z = tmp;
}
// outputs the sorted numbers
cout << "The sorted numbers are: ";
cout << x << " " << y << " " << z
<< endl;
}
Output:
// the program attempts to sort three integers // in increasing order, it is incomplete //...
Objective: 1. Understand sorting algorithm 2. Implement bubble sort in C++ Check slides for a template of the solution, if you need Write a program that asks users to input 10 integers into an array, write a function that takes the array as its argument, use bubble sort to sort the array and output the sorted array in increasing order. #include <iostream> using namespace std; C:IWINDOWSSystems2cmd.exe lease input 10 integers: void bubblesort(int a[10]) int help; int b[10]; for (int i...
Question 19 4 pts Using the program below, please complete the program by adding 2 functions as follow: 1. A function named getAverage that calculates and returns the Average. 2. A function named getMaximum that returns the maximum of the three numbers. Make sure to use the proper data types for all variables and functions. #include <iostream> using namespace std; //function getAverage //function getMaximum int main(int argc, char** argv) { int x, y, z; cout << "Enter three whole numbers:...
c++, data structure Write a solution to test 2 problem 3 that uses selection sort to sort the items in the vector of integers. #include <iostream> #include <iterator> #include <string> #include <random> using namespace std; void insertionSort(int a[], int N) { int sorted = 0; for (int sorted = 0; sorted < N - 1; ++sorted) { int item_position = sorted + 1; int item = a[item_position]; while (item_position > 0 && a[item_position - 1] > item) { a[item_position] =...
read in numbers into array , print out, sort - my program reads in and prints out but crashes before the sort - crashes after it prints out the scores - *important I have to use pointers!!!! c++ #include <iostream> using namespace std; void sortarray(int *tarray, int ); void displayarray(int *[], int); void averageshowarray(int *[], int); int main() { int Size; int count; cout << "enter the size: " << endl; cin >> Size; int...
// demonstrates separating digits with a remainder operator // Mikhail Nesterenko // 01/22/2016 #include <iostream> using std::cin; using std::cout; using std::endl; int main(){ cout << "Input number from 01 to 50: "; int number; cin >> number; const int singles = number % 10; const int tens = number / 10; cout << "tens: " << tens << endl; cout << "singles: " << singles << endl; You may assume that the user never inputs a number less than 1...
16 Points) Question 3 Write down the outputs of the following program into the provided table include <iostream> using namespace std; void fun I(int a); int fun2(int a, int b); int x-3: int main) int x-1,y 0,z-2; x-fun2(y,z); cout sx fun 1 (z); cout (#xtytz(endl; y-fun2(x,x); cout <exty+zscendl; system("pause"); void fun 1 (int a) int fun2(int a, int b) int static c2; return atx; 16 Points) Question 3 Write down the outputs of the following program into the provided table...
Question text Find four problems with this program: ------------------------------------------- using namespace std; // this program inputs three integers, determines if negative, positive, or zero int main() { cout << "Enter an integer" << endl; cin >> input; if (input < 0); cout << "The number is negative." endl; else if (input > 0) cout << "The number is positive" << endl; else cout << "The number is zero" << endl; return 0; } programm c++ please and thank you
When running the program at the destructor an exception is being thrown. Can someone help me out? vararray.h: #ifndef VARARRAY_H_ #define VARARRAY_H_ class varArray { public: varArray(); // void constructor int arraySize() const { return size; } // returns the size of the array int check(double number); // returns index of element containg "number" or -1 if none void addNumber(double); // adds number to the array void removeNumber(double); // deletes the number from the array ...
#include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...
I am trying to write this code which asks "Write a program that ask the user, the question: What is a^b? //The program generates two signed integers and gives the user four attempts to get the correct answer //a=- , b = + //a= + , b = - " So far this what I wrote. I am not sure how to do this correctly. #include<iostream> #include<cstdlib> #include<ctime> using namespace std; int main() { srand(time(0)); int guess,a,ans,b, k;...