Code : : Blocks for Beginners [1] | Understanding basic C programming structure and function

What Will I Learn?
In this tutorial, you will be able to :
- use the correct syntax for preprocessor directive, main function, and declaration statements;
- use
printf()
andscanf()
functions; and, - create a simple C program to convert Kilograms to pounds.
Requirements
To be able to follow this tutorial, you need to have the following tools:
- A desktop PC or laptop with Windows (7, 8, 10) operating system; and,
- An installed GCC Compiler and Code:: Blocks Open Source cross-platform IDE software.
If you do not have the following software, you can download the Code:: Blocks software from codeblocks.org. For the GCC Compiler, you can download a MinGW compiler from mingw.org.
Difficulty
Basic
General Structure of a C program
The simplest computer programs perform three basic operations:
- get the input from the keyboard
- process the input data
- display the results on the screen
The most basic form of a C program follows a very simple format:
preprocessor directives
main function
{
declaration
statement
}
Tutorial Content for the simple C program to convert kilogram to pounds
Part 1: Creating a New Project
1 | Open Code:: Blocks from your desktop or from your windows menu. Click to start a new project.

2 | Click from "New from template" wizard. Then click
.

3 | Click from the Console application wizard.
4 | Select language to C and click .

5 | Type in the project title in the Console application wizard then click .

6 | Click
to finalize the creation of a new project.


Part 2: Coding the simple C program for converting kilograms to pounds (includes discussion).
1 | Your first C program will starts with a preprocessor or compiler directives. This includes standard header #include <stdio.h
and standard library #include <stdlib.h>
.
2 | Define constant variable for your program by using the syntax #define kg_to_lbs 0.454
. Variable names is used to indicated data values. It may change based on actions in the program.
3 | C progam is a step-by-step programming by which it execute program from top to bottom. The main body of the program is enclosed inside { and } brackets. The proper syntax for the main body of the program should be:
int main()
{
//program codes here//
return(0)
}
4 | Identify variables names to be used in to the program float pounds, kilograms;
.
int main()
{
float pounds, kilograms;
return(0)
}
5 | To ask for the weight in pounds, type in : printf("Enter weight in pounds:");
.
scanf("%f", £s);
printf()
function is used to display text in the C program; and,scanf()
is used to input data to the program. It allows to ask floating point number and then strored to a memory location pounds. This is done by the placeholder %f (recieve data) and £ (store data to pounds).
Now include printf and scanf to int main().
int main()
{
float pounds, kilograms;
printf("Enter weight in pounds:");
scanf("%f", £s);
return(0)
}
6 | To convert pounds to kilogram, you need to input a kilograms = kg_in_lbs*pounds;
. Add the code after scanf() function.
int main()
{
float pounds, kilograms;
printf("Enter weight in pounds:");
scanf("%f", £s);
kilograms = kg_in_lbs*pounds;
return(0)
}
7 | Now, to show the result, type in after the formula printf("%.2f Pounds is equal to %.2f Kilograms.\n", pounds, kilograms);
.
int main()
{
float pounds, kilograms;
printf("Enter weight in pounds:");
scanf("%f", £s);
kilograms = kg_in_lbs*pounds;
printf("%.2f Pounds is equal to %.2f Kilograms.\n", pounds, kilograms);
return(0)
}
8 | Type in the codes above to the main.c on the code:: blocks.

9 | Click
to build the program.

10 | Click to run the program.
The result of the program.


Thank you for reading this tutorial. I hope you learn something. Stay tune for the next Code:: Blocks for Begginer tutorial series.
@juecoree
Posted on Utopian.io - Rewarding Open Source Contributors
Your contribution cannot be approved because it does not follow the Utopian Rules.
I can see your effort but i'm sorry.
You can contact us on Discord.
[utopian-moderator]
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by juecoree from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.