Question #38846

write a c++ program that calculates energy by using speed of light and given mass(E=m(c*c)).
1

Expert's answer

2014-02-06T10:32:04-0500
#include <iostream>
using namespace std;
static const double LIGHT_SPEED = 299792458;
int main()
{
    double m;
    cout << "Enter a mass in kilograms: ";
    cin >> m;
    if (m < 0)
    {
        cout << "Mass can't be negative." << endl;
        return -1;
    }
    double E = m * LIGHT_SPEED * LIGHT_SPEED;
    cout.precision(3);
    cout << "The energy is " << E << " joules." << endl;
    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 the first!
LATEST TUTORIALS
APPROVED BY CLIENTS