Computer Science, asked by subhamneupane06, 7 months ago

write a program to convert metre into centimetre​

Answers

Answered by naglaxmimhetre
0

Answer:

int main()

{

int distance, ans;

printf("enter distance in meters:") ;

scanf("%d", &distance) ;

ans=100*distance;

printf("%dcm", ans) ;

return 0;

}

Answered by Anonymous
6

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 \tt{float(inp ut())} 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 \tt{float()} function since user can also enter the decimal value, values could always have the possibility of being in decimals. If we use \tt{int()} 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 \tt{float()} as both integers and decimals are accepted.

\rule{300}{1}

The Program

m=float(input("Enter the measure in meters: "))

cm=m*100

print("The meter is equivalent to",cm,"centimeter.")

\rule{300}{1}

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.

\rule{300}{1}

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.

\tt{print(float(in put("Enter\ the\ measure\ in \ meters: "))*100, "centimetre.")}

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.

Similar questions