static_cast
Completed
Read two integers a and b. Print a / b (integer division) and the exact quotient with 3 decimals using static_cast<double>.
Input
Two integers (b ≠ 0).
Output
Two lines.
Example
Input
7 2
Output
3 3.500
Editor
C++
Hints
static_cast<double>(a) converts a before the division.
Solution explanation
static_cast is the explicit, searchable C++ way to convert types.
Show solution
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a / b << "\n";
cout << fixed << setprecision(3) << static_cast<double>(a) / b << "\n";
return 0;
}