Answer:
// program in C++.
#include <bits/stdc++.h>
using namespace std;
// main function
int main() {
// variable
float n;
cout<<"Enter the initial value:";
//Read the input from the user
cin>>n;
//Declare variables for storing values at 6, 12 and 18 hours
float hours_6, hours_12, hours_18;
//Set precision level of floating point number
cout << fixed;
cout << setprecision(6);
//calculate values at 6, 12 and 18 hours
hours_6 = n / 2.0;
hours_12 = hours_6 / 2.0;
hours_18 = hours_12 / 2.0;
//display the output
cout<<"After 6 hours: "<<hours_6<<"mg"<<endl;
cout<<"After 12 hours: "<<hours_12<<"mg"<<endl;
cout<<"After 18 hours: "<<hours_18<<" mg"<<endl;
return 0;
}
Explanation:
Read an input from the user. Set the precision to 6 for displaying the result up to 6 decimal places. The first half life at 6 hours can be calculated by dividing the input by 2. The half life at 12 hours can be found out by dividing the half life value at 6 hours by 2. Similarly at 18 hours, we find the half life value by dividing the half life value at 12 hours by 2.
Output:
Enter the initial value:100
After 6 hours: 50.000000 mg
After 12 hours: 25.000000 mg
After 18 hours: 12.500000 mg