write a program to convert metre into centimetre
Answers
Answer:
int main()
{
int distance, ans;
printf("enter distance in meters:") ;
scanf("%d", &distance) ;
ans=100*distance;
printf("%dcm", ans) ;
return 0;
}
M into CM - Python
Since we are not given/mentioned in the Question that by what programming language we write the required program, so here we are using Python program to convert meter into centimetre.
What we need to do
We would take a user float input first, to accept the meter from the user. We know that when we want the user to type in a decimal value, we use function.
After that we know that, when we convert the meter value from centimetre we always multiply the meter value by 100. So here also we will multiply the meter value [which we accept from the user] by 100.
We then print out the centimetre value with the required result.
Why we use float() function
We use function since user can also enter the decimal value, values could always have the possibility of being in decimals. If we use function as the data type and a user enters a decimal value or integers, the program would result in an error. To be on the safer side, we use as both integers and decimals are accepted.
The Program
m=float(input("Enter the measure in meters: "))
cm=m*100
print("The meter is equivalent to",cm,"centimeter.")
The Output
If you run the given program then the output of the given program will be as follows:
Enter the measure in meters: __
The meter is equivalent to __ centimetre.
Suppose that if you have entered the measure of meter as 5, then the output of the given program will be as follows:
Enter the measure in meters: 5
The meter is equivalent to 500.0 centimetre.
Do you know
We can also write the above program in one line. Excited to know that how to write the one liner program?
So I'm pasting the same program with some changes for one liner program.
If you run this program, then the output of the given program will be as follows:
Enter the measure in meters: 5
500.0 centimetre.