60 664
Assignments Done
97,7%
Successfully Done
In April 2018

Answer to Question #67252 in C++ for Mian Saqlain

Question #67252
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++;
Expert's answer
#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;
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions