Professional Documents
Culture Documents
Introduction
Introduction
Why do we need it?
Where can we use it?
How can we write the code?
How the code is organized?
In this subject we will program in C language.
C language
Why do we learn C language as a structural
programming language?
C based languages
C++
C#
Java
As a compiler you can use CodeBlocks, or any other
C compiler (http://www.codeblocks.org/)
Defining variables in C
There are multiple types of variables
integer (Real numbers)
float (Decimal point numbers)
char (Characters, single or string)
Example
void main()
{
int a;
float p;
p=1.0/2.0; /* p=0.5 */
a=5/2; /* a=2 */
p=(1/2)+(1/8); /* p=0.0 */
p=3.5/2.8; /* p=1.25 */
a=p; /* a=1 */
a=a+1; /* a=2 */
}
Operators in C
Math operators
Addition +
Subtraction
Multiplication *
Division /
Power ^
Logical operators
Equal ==
Not equal !=
Greater > (Greater equal >=)
Smaller < (Smaller or equal <=)
Example
Write a program that will calculate this mathematical
expression x = 3/2 + (5 46*5/12)
#include <stdio.h>
void main()
{
float x;
x = 3/2 + (5-46*5/12);
printf(The value of x is %f\n, x);
}