Statements,Operators &Control Structures

AlonTashobya 4 views 15 slides Oct 19, 2025
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

The use of Statements, Operators & Control Structures
in C programming


Slide Content

LECTURE 3: Statements, Operators & Control Structures

Statements A statement is a complete direction instructing the computer to carry out some task e.g. x =2+3 ; Differentiate between a Single Statement and a Compound Statements { block of 2 or more statements} . Expressions: In C, an expression is anything that evaluates to a numeric value. Expressions can range from simple to complex .

The Fundamental Operators in C Operators in C language can be grouped as follows: Assignment Operator . Arithmetic Operators Unary Mathematical operators . Relational operators . Logical operators .

Arithmetic Operators Examples; / (Division) e.g. z=x/2 ; - (Subtraction) e.g. z=x-2 ; + (Addition) e.g. z=x+2 ; % (Modulus) e.g. z = x%2; (Multiplication) e.g. z = x*2 ; Assignment Operator (=)

Unary Operators Post- Increment/Pre - Increment Decremental Operator (--) e.g. a-- = a-1 ; ( Post ) --a= a-1 ; ( Pre ) Incremental Operator (++) e.g. a++ = a+1 ; ( Post ) ++a = a+1 ; ( Pre )

Relational Operators Examples; >, ( Greater Than ) e.g. x>y <, ( Less Than ) e.g. x<y >= , ( Greater or Equal To ) e.g. x>=y <= , ( Less or Equal To ) e.g. x<=y == , ( Equality Operator ) e.g . x==y !=, ( Not Equal To ) e.g. x!=y

Logical Operators Examples; Logical AND (&&) e.g. {(a<b) && (b<c)} Logical OR (||) e.g. {( a<b) || (b<c )} Logical NOT (!) e.g. {!(a>b)}

Control Structures If condition If ….else Multiple Case Selection Structures: If …… else if…… Switch * ( Read! )

The if statement Syntax: if (condition) { statement (s); } Example: if (a>=b) { x =b-a; }

If….else Syntax: if (condition ) { statement1 (s); } else { statement2 (s); } Example : if (a>=b) { x=b-a; } else { y=a-b; }

Multi Selection Case Syntax: if (Condition1) { statement1; } else if (condition2) { statement2 } else if (condition3) { statement3 } else …… …. Main() { char ch; if (ch= =‘m’){ printf (“Monday”); } else if (ch = =“t”){ printf (“Tuesday”);} else if (ch = =‘w’) { printf (“Wednesday”); } else if (ch= =“h”) { printf (“Thursday”); } else if (ch= =‘f’ ) { printf (“Friday”); } else if(ch= =‘a’) { printf (“Saturday”); } Else if (ch= =‘s’) { printf(“Sunday”); } Else printf (“Not a day of the Week”); } }

Other Operators Condition Operator: Syntax: exp1?exp2:exp3 z= (x>y)? X:Y ; Generally: { Z= (Condition)? True: False;} Comma Operator: X= (a++, b++);

Read About! Operator Precedence of Operators. Evaluation of Complex Expressions Use of the printf, scanf function in a computer program.

Assignment (2) Write a C program to solve

Read About! Using Flow Charts in Modeling of Computational Problems. Repetitive Structures(Iterative Structures) or Loops.
Tags