English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm doing a simple 'C' program to convert meter to km., in., and cm. How do I make the answers with at least 3 decimal points?

2007-01-05 22:03:55 · 3 answers · asked by ynnas 1 in Computers & Internet Programming & Design

3 answers

Im very sorry but Im not good at C++ but I can write a program in Java.
import java.io.*;
class distance
{
public static void main(String args[])throws IOException
{
int m, km;
double cm=0.000;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.pritnln("Enter the value in metres");
m=Integer.parseInt(br.readLine());
km=m*1000;
cm=m/100;
System.out.println("The value in Km="+km);
System.out.println("The value in cm="+cm);
}
}

2007-01-06 03:58:04 · answer #1 · answered by Nitin T F1 fan 5 · 0 0

Conversions in the metric system are very straighforward if you know what the different prefixes mean. In your case, centimeter (preifx = centi) means 100th. So there are 1 centimeters is 1/100th of a meter or 100 centimeters in one meter Kilometer (prefix=kilo) means 1000. So a kilometer is 1000 meters. Therefore, ? km = 224.3cm x? We need to make sure our units are the same on both sides... so ?km = 22.4cm x 1km/(100cm) .224 km == (22.4/1000) km we see that the cm cancels out so we have km on both sides (km=km) Note: This is all you need to remember for ALL dimensional analysis or conversion problems... If you do that, you do not have to remember when you divide or multiply.. just make sure that your units work out.

2016-05-22 22:27:54 · answer #2 · answered by Anonymous · 0 0

don't use integers and when you put the variable in the writeline bit there is a tag that allows you to control the output - sorry to be vague but I'm going back some 15 years or so !

2007-01-05 22:06:32 · answer #3 · answered by cool_clearwater 6 · 0 0

fedest.com, questions and answers