Best Cell Phones

Meter to feet conversion

Meter to feet conversion - C Programming Example

This program is an example of C program code that converts an input from feet unit to meter unit.

C Programming Code

    float a,b,c;
    printf("Input the length in meter \n");
    printf("The length converted to feet is %f",c);

Output of the code

Meter to feet conversion - C programming example
Meter to feet conversion - C programming example 

Explanation of the code

·        #include<stdio.h>
Ø  This are called header file.A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source filesThe C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header <stdio.h>.In the other hand  <conio.h> is a C header file used mostly by MS-DOS compilers to provide console input/output. It is not part of the C standard library or ISO C. This header declares several useful library functions for performing "console input and output" from a program.

·         main()
Ø  In C, program execution starts from the main() function. The main function can in-turn call other functions. When main calls a function, it passes the execution control to that function. The function returns control to main when a return statement is executed or when end of function is reached.
·            float a;
Ø  float is a variable or data type. A variable declared to be of type float can be used for storing numbers which have decimal points. Here we declare “a,b,c
variable in floattype.
·         printf() function
Ø  C uses printf() function to write from the input devices. This function has been declared in the header file called stdio.h . Any text written within the pair of quotes ("") is displayed as such by printf() function on the screen. 
·         scanf() function
Ø  This function is used to get input from the user of the program. scanf(“%f”,&a”) is used here. So, this program will read in a float value for “a” variable that the user enters on the keyboard (%f is for float values. As there is “&a”, the number user enters will be the value of “a” variable).

Then b is declared.
We know 1 meter= 3.2808399 feet. So if the input is a, the converted length will be a*3.2808399 or in this program a*b
Hence, c is declared as c= a*b.
    printf("The length converted to feet is %f",c);
After that printf is included to show the converted length as output. Finally getch(): is written top end the program.

You may also like

No comments

Powered by Blogger.