0% found this document useful (0 votes)
5 views18 pages

Lecture 2

Uploaded by

farless373
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views18 pages

Lecture 2

Uploaded by

farless373
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

PROGRAMMING

CONCEPTS
CS 8104
COURSE CONTENT
 Operators and Expressions

 Control Flow Statements

 Functions
OPERATORS AND
EXPRESSIONS
 Operators are symbols that are used to perform

specific operations on variables and values.


 There are several types of operators in C such as;

 Arithmetic operators

 Relational operators
OPERATORS AND
EXPRESSIONS
 Cont..

Logical operators

Bitwise operators

Assignment operators

Miscellaneous operators
ARITHMETIC OPERATORS
 Are a type of operator in C programming that

are used to perform mathematical operations.


 The arithmetic operators in C include:

Addition operator (+)

Subtraction operator (-)


ARITHMETIC OPERATORS
 Cont..

Multiplication operator (*)

Division operator (/)

Modulus operator (%)


ARITHMETIC OPERATORS
 Cont..

 Here is an example of how to use arithmetic

operators in C programming:
ARITHMETIC OPERATORS
 Cont..

#include <stdio.h>
int main() {
int a = 10, b = 5, c;
c = a + b;
ARITHMETIC OPERATORS
 Cont..

printf("a + b = %d\n", c);


c = a - b;
printf("a - b = %d\n", c);
c = a * b;
ARITHMETIC OPERATORS
 Cont..

printf("a * b = %d\n", c);


c = a / b;
printf("a / b = %d\n", c);
c = a % b;
ARITHMETIC OPERATORS
 Cont..

printf("a % b = %d\n", c);


return 0;
}
RELATIONAL OPERATORS
 Are used to compare the values of two
operands.
 They return a boolean value (true or false)

based on the comparison.


 The following are the relational operators in C:
RELATIONAL OPERATORS
 Cont.. < (less than)

== (equal to) >= (greater than or

!= (not equal to) equal to)

> (greater than) <= (less than or equal

to)
LOGICAL OPERATORS
 These operators combine two expressions
logically, returning a boolean value. Examples
are such as;
Logical AND (&&)

Logical OR (||)

Logical NOT (!)


C PROGRAMMING EXAMPLE
 Example 1

#include <stdio.h>
int main() {
int a, b;
printf(“Enter the value of a:\n”);
scanf(“%d”,&a);
C PROGRAMMING EXAMPLE
c = a + b;
printf(“Enter the value of b:\n”);
scanf(“%d”,&b);
printf(“a+b = %d\n”,a+b);
printf(“a-b = %d\n”,a-b);
C PROGRAMMING EXAMPLE
 Cont..

printf(“a*b = %d\n”,a*b);
printf(“a/b = %d\n”,a/b);
printf(“a%b = %d\n”,a%b);
return 0;}
C PROGRAMMING EXAMPLE
 Cont..

printf(“a*b = %d\n”,a*b);
printf(“a/b = %d\n”,a/b);
printf(“a%b = %d\n”,a%b);
return 0;}

You might also like