Question #43991
/* PROGRAMMING ASSIGNMENT 1:
Input: Enter five real numbers.
Output: Find the sum, product and relationship of each pair of numbers
e.g: input:
1,2,3,4,5
output:
The sum are:3,4,5,6,5,6,7,7,8,9
The products are:2,3,4,5,6,8,10,12,15,20
The relationship are:
1 < 2 1 < 3 1 < 4
1 < 5 2 < 3 2 < 4
2 < 5 3 < 4 3 < 5
4 < 5
1
Expert's answer
2014-07-07T15:31:39-0400
#include <iostream>void sum(int* array, int size ) {    std::cout << "The sum are: ";    for ( int j = 0; j < size; j++) {        for ( int i = j+1; i < size; i++ ) {            std::cout << array[i] + array[j] << " ";        }    }    std::cout << std::endl;}void product( int* array, int size ) {    std::cout << "The product are: ";    for ( int j = 0; j < size; j++) {        for ( int i = j+1; i < size; i++ ) {            std::cout << array[i] * array[j] << " ";        }    }    std::cout << std::endl;}void readNumbers( int* array, int size ) {    for ( int i = 0; i < size; i++ ) {        std::cin >> array[i];    }}void relations ( int* array, int size ) {    for ( int j = 0; j < size; j++) {         for ( int i = j+1; i < size; i++ ) {            if (array[j] > array[i]) {                std::cout << array[j] << " > " << array[i] << std::endl;            } else {                std::cout << array[j] << " < " << array[i] << std::endl;            }        }    }}int main() {    const int SIZE = 5;    int *array = new int[5];    std::cout << "Enter 5 real numbers." << std::endl;    readNumbers(array, SIZE);    for ( int i = 0; i < SIZE; i++ ) {        std::cout << array[i] << " ";    }    sum(array, SIZE);    product(array, SIZE);    relations(array, SIZE);    return 0;}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS