Write a program that does the following: a. Prompts the user to input five decimal numbers. b. Prints the five decimal numbers. c. Converts each decimal number to the nearest integer.
Please do it in c++;
1
Expert's answer
2017-04-11T01:53:07-0400
#include<iostream>
using namespace std;
int main() { const size_t n = 5; double data[n];
cout << "Enter 5 numbers:\n";
for (size_t i = 0; i < n; i++) { cout << "number[ " << (i + 1) << "] = "; cin >> data[i]; }
cout << "U`ve entered 5 numbers: "; for (size_t i = 0; i < n; i++) { cout << "number[ " << (i + 1) << "] = " << data[i]<<" "; }
int converted_data[n];
for (size_t i = 0; i < n; i++) { converted_data[i] = round(data[i]); }
cout << "\nConverted 5 numbers: "; for (size_t i = 0; i < n; i++) { cout << "number[ " << (i + 1) << "] = " << converted_data[i] << " "; } system("pause"); return 0; }
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