Coding With Yash

C Program To Convert Meter To Feet

convert meter to feet

Hello programmers, this is module no.3 of our ongoing “Programming in C” series. In this post, we will write and understand the C program to convert meter to feet. Just like we used to do in Maths in our school days the same concept we will use here. First, we will ask the user to enter any value of his choice that he wants to convert in feet with an appropriate display message with the help of printf() functions.

Once the user enters the value that needs to be converted, we will grab that value and assign it to the declared variable with the help of the scanf() function. Now the basic Maths conversion that we used to do in our school days, is the same conversion we will do here.

Explanation: c program to convert meter to feet

Now let us understand the entire code line to line, In the first line we included all the standard input and output files, and in the second line we have included all the console input and output files inside the header using the #include<stdio.h> and #include<conio.h>.

By doing this we will be free to use scanf(), printf(), clrscr(), and getch() functions without any error. And if you want to know more in detail what is the use of #include<stdio.h> and #include<conio.h> and why we always use them in our program, what will happen if we don’t use them, and what happens when we use them. We have covered all the entire things in our blogs. We have provided the link at the bottom of this blog you can check that out too.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float mtr, foot;

printf("enter the value in to meter");
scanf("%f", &mtr);

/* use this conversion
1 meter = 3.28084 */

foot = mtr * 3.28084;

printf("the value after conversion in foot is %f", foot);
getch();
}

Turbo C++ Programming Window

Here is the exact code that you are gonna see on your code editor, doesn’t matter which code editor you are using, the logic will be the same for all of those. In my case, I am very much comfortable with Turbo C++ for doing programming in c as well as for C++ programs.

One more thing which is very important and is a good practice to follow for programmers is to add comments on the program. As you can notice below picture I have mentioned a comment that is “C Program to convert meter to feet” in the very starting and in between also I have commented the formula for the conversion.

c program to convert meter to feet source code

Turbo C++ Output Window

This will be the output that you will get once after the successful compilation and running of your program. As per our code, you will first get a display message which will ask you to enter any value of your choice that you want to convert in feet. Now enter the value and hit enter then you will see the desired result.

And if you are not getting the desired result then check your code again, if there is any error or mistake fix it first then save it, and again compile and run it then you will see the desired output. remember to use the correct datatype as in this code on dividing the number while conversion it must be possible that you get floating values, so assign the variables accordingly.

c program to convert meter to feet output

If you want to perform the opposite of the above code, let’s say you want to convert the values from feet to meter then we have another program for that solution too, kindly have a look at that solution also.

Read out C program to convert feet to meter to learn the opposite of the above question.

Conclusion:

We hope that you have got the code and now you can easily perform basic maths conversion in c language. If you find this code worth reading then please share it with some who needs it. And as always if you guys are facing any issues in any of your code then you can share it with me using comments, I will be more than happy to help you out.

Enjoy your coding journey 🙂

 

Recent Posts