Chapter 2-Introduction To C Programming Language
Chapter 2-Introduction To C Programming Language
scanf("%d", &n);
4
Examples of statements to process data:
area= 3.14 * r *r ;
m= q*p*(1-d/100.0);
5
Proper steps to write a program :
1. Understand the problem by:
• Knowing the inputs.
• Knowing the required outputs.
• Defining relationships between inputs
and outputs and identifying the required
processing.
20
Note:
C language is a case sensitive.
Ex: identifiers mark, MARK , Mark are
considered as different identifiers.
21
Examples of some Valid Identifiers:
name
PI
value1
_9_3
Student_Id
Examples of some Not Valid Identifiers:
float
6time
Student name
M,Y
do
full-mark 22
2.6 Variables Declaration :
-Any variable must be declared before using it
in the program.
-When a variable is declared, a location in
computer memory will be assigned by the
complier to store that variable.
-Any changes on the value of that variable will
be stored in this memory.
Examples:
25
2.7 Constants Declaration :
•A constant may be declared before using it
in the program.
28
2.9 Assignment Statements:
•They represent processing statements in C
programs where different calculations can be
performed.
Syntax:
variable = expression;
The operator “=“ is called the Assignment
operator.
Example:
{ float t, x=91.55;
int y=-4;
t= -y + x/5 ;} 29
Example: How to write the assignment
statement to calculate x from the
following equation:
y 2 + x =95
2
Answer:
x=sqrt( 95 – y*y);
30
2.10 Formatted Output on the screen:
•represents one of the methods used in C
programs to output (print) results on the
computer screen .
•The library function printf( ) is used for
that purpose.
The Number =
34
In most of our programs we will use the
following escape sequences.
37
• Any Format Specifier will be replaced by
a value of either constant or variable or
expression that is written after the
Format Control String and that value will
be printed on the screen.
Some Format Specifirs are:
38
39
40
41
42
2.11 Formatted Input from Keyboard:
•Represents one of the methods used in C
programs to input different types of variable
data from the keyboard to the program.
48