round c++
#include <iostream>
#include <cmath>
int main() {
double num = 10.49;
double roundedNum = round(num);
std::cout << "Original number: " << num << std::endl;
std::cout << "Rounded number: " << roundedNum << std::endl;
return 0;
}
Explanation:
- #include <iostream>
: Includes the input/output stream library to enable input and output operations.
- #include <cmath>
: Includes the cmath library that provides mathematical functions like round
.
- int main() { }
: The main function where the execution of the program begins.
- double num = 10.49;
: Declares a variable num
of type double and assigns the value 10.49
to it.
- double roundedNum = round(num);
: Calls the round()
function from the cmath library to round the value stored in num
and assigns the result to the variable roundedNum
.
- std::cout << "Original number: " << num << std::endl;
: Outputs the original value of num
to the console.
- std::cout << "Rounded number: " << roundedNum << std::endl;
: Outputs the rounded value of num
to the console.
- return 0;
: Indicates successful completion of the main()
function and the program terminates with a return status of 0.