What Will I Learn?
- You will learn Usage of loops
- You will learn Usage of C libraries
- You will learn where and how to use C language
Requirements
- Dev-C Program you can download by clicking
HERE - Interest on coding
Difficulty
- Basic
Tutorial Contents
Why use "C" language in all of that language?
C language is one of the oldest language in the game which launched in 1972 and still in use of a lots of projects.C language is launcher of big projects that i am going to list below.The programs below mostly made up with C language when first they launched.
- Microsoft Windows
- Linux
- Mac
- Doom (game)
- Quake 1,2,3 (game)
These are the little list of the programs that written in C language.Also most of the programming languages that are popular is based on "C" language ; c#,java,javascript,phyton and more.
How to program on C
First of all you must define a library depending on what type of program you are going to write.Since we just begin C language i will show the very first libraries that we need to know.
<Stdio.h> = This library basically defines input and output functions that comes from user.
Example : "Printf("Enter A Number"); // "Printf" is used to print anything you want on screen
: "Scanf("%d"); // "Scanf" to scan what user entered and i will tell about %d at below.
<Math.h> = This library is used to make mathematical operations.
Example : For Logarithm problems we use "log" function.
<Stdlib.h> = This library is used for string handling and to convert variables.
These are the libraries you need to know in first step,if you are asking yourself where am i going to use these let me show you.
Let's write our very first program on C language.First of all after deciding what kind of program we are going to write then we define libraries,but in "Dev" first two libraries will be already defined.
We started our program now we will write down some code.This program will find the average score of a 2 member class.
First i defined three integers s1 and s2 are my students and average is to show average.This variables can be defined in "double" type too."Double" and integers diffrence is if you define a variable in double type the number of that variable can be fractional.
I ask user to write first students result with using "printf" and used "\n" to create a new line then used "scanf" to assign users input to the variable.
Note : "%d" is used to define an integer in scanf method.
Then i made a addition and divided general score to two and printed it to the user "printf("Average Score of Class : %d",average);" in the last part i assigned "average" in to the %d in printf.
#include <stdio.h>
#include <stdlib.h>
int main() {
int s1,s2,average;
printf("Please enter first students test result\n");
scanf("%d",&s1);
printf("Please enter second students test result\n");
scanf("%d",&s2);
average = ( s1 + s2) / 2;
printf("Average Score of Class : %d",average);
return 0;
}
Here Is The Few Of The Operators In C Language
&& = Means "and" in C language
Ex : s1 && s2
|| = Means "or" in C language
Ex : if ( a>10 || a < 15)
! = Means "not" in C language,reverses the situation of statement.
Ex : a=b ; a equal to b
!(a=b) ; a is not equal to b
This is the first step to learn operators we need to know at the moment.Now let's take a look at arrays.
Arrays
When you assign few variables in memory,these variables can be anywhere in memory and will take longer time to find these also why not make them and save in-line.Let's see an example;
int money[10] ; This is an array and this array can hold 10 members inside.
But if you want to choose members of array yourself this is how you do it;
int money[10] ; {5,2,5,6,7,324234,455,567567,456456,78678};
In the example above i assigned each member of array a new value.Arrays Does Not! start from 1,arrays start from 0.For example you want to assign the 6th member of 10 member array.Would you do it like;
int money[6] ; {150}; Like this ?
OR
int money [5] ; {150}; Like this?
Answer Is : The second one.Since arrays starts from 0 my sixth member must be 5 so correct answer is second one.
Next Tutorial
In the next tutorial we will focus on arrays and how to use them.Arrays are one of the most important thing in C language to make our job easier also we will make an example program.
Posted on Utopian.io - Rewarding Open Source Contributors
Your contribution cannot be approved because it does not follow the Utopian Rules.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit