How to write a program that accepts 6 pairs of values from the user and then calculates and stores the difference of each pair of values in an array.The array of calculated values should then be sorted into ascending order and printed on screen?
1
Expert's answer
2011-06-10T07:47:46-0400
#include <iostream> using namespace std;
const int ARR_SIZE = 6;
void Sort (float array[]) // Function for bubble sort of the array { bool sorted;& // Flag for indicating while the array is sorted float temp;& // Temp variable for storig values
do { & sorted = true; & for (int i = 0; i < ARR_SIZE-1; i++) & { if (array[i+1] < array[i]) { sorted = false; temp = array[i]; array[i] = array[i+1]; array[i+1] = temp; } & } } while (!sorted); }
void Display (float array[])& // Function for displaing array of values { system("cls"); cout<< "Elements of the array in ascending order: "<< endl;
for (int i = 0; i < ARR_SIZE; i++) { & cout<< array[i]<< endl; } }
int main () { float x, y;& // Variables for storing pairs of values float array[ARR_SIZE]; // Arrays for storing differences between values cout<< " **Enter values separating it with spaces\n"; for (int i = 0; i < ARR_SIZE; i++) { & cout<< "Enter "<< i+1<< " pair of numbers\n > "; & cin >> x >> y; // Getting values from user (values must be split by space) & array[i] = x - y; // Calculating of difference }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment