Write a program to do the following:
a) Store distance in metres in an int variable.
b) Convert the metres into centimetres and store
in a different variable.
c) Convert the metres into millimetres and store
in a different variable.
d) Print all the details by using appropriate
messages
Hint: 1 metre = 100 centimetres and 1
centimetre = 10 millimetres.
Answers
Answered by
0
Answer:
be given to the program, and the value will be stored in the variable distance. Finally, on the last line, we use another cout statement to print ...
Answered by
2
Answer:
Using Java, the códe goes like -
import java.util.*;
public class Main {
public static void main(String[] args) {
double m,cm,mm;
System.out.print("Enter distance in metres: ");
m=(new Scanner(System.in)).nextDouble();
cm=100*m;
mm=cm*10;
System.out.println("Given Length: "+m+" m");
System.out.println("Length in cm: "+cm+" cm.");
System.out.println("Length in mm: "+mm+" mm.");
}
}
Note:
- Here, m stores the length in metres.
- To convert the length into metres, we will simply multiply the length entered with 100. Result obtained is stored in cm variable.
- Again, cm is multiplied by 10 to get the length in millimetres which is stored in mm.
- At last, the result is displayed on the screen.
See the attachment for output.
•••♪
Attachments:
Similar questions