SlideShare a Scribd company logo
1 of 22
Download to read offline
C Operators
Types of operators in C
Arithmetic Operators
Operator Name Description Example
+ Addition Adds together two values x + y
- Subtraction Subtracts one value from another x - y
* Multiplication Multiplies two values x * y
/ Division Divides one value by another x / y
% Modulus Returns the division remainder x % y
++ Increment Increases the value of a variable by 1 ++x
-- Decrement Decreases the value of a variable by 1 --x
#include<stdio.h>
int main()
{
int a, b, add, sub, mul, div, rem;
printf("Enter a, b values : ");
scanf("%d%d",&a,&b); // Reading two values
add=a+b; // Addition Operator
sub=a-b; // Subtraction Operator
mul=a*b; // Multiplication Operator
div=a/b; // Division Operator
rem=a%b; // Remainder (Modulo) Operator
printf("Result of addition is=%dn", add);
printf("Result of subtraction=%dn", sub);
printf("Result of multiplication is=%dn", mul);
printf("Result of division is=%dn", div);
printf("Result of remainder=%dn",rem);
return 0;
}
Assignment Operators
Operator Example Same As
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
&= x &= 3 x = x & 3
|= x |= 3 x = x | 3
^= x ^= 3 x = x ^ 3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3
Assignment operators are
used to assign values to
variables.
Comparison
Operators
• Comparison operators are used to
compare two values (or variables)
Operator Name Example
== Equal to x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y
Logical
Operators
• Used to determine the logic between
variables or values
Operator Name Description Example
&& Logical and Returns true if both
statements are true
x < 5 && x < 10
|| Logical or Returns true if one of the
statements is true
x < 5 || x < 4
! Logical not Reverse the result,
returns false if the result
is true
!(x < 5 && x <
10)
Special Operators
Use of sizeof() operator
Example showing use
Operator

of Relational
#include <stdio.h>
int main()
{
int m=40,n=20;
if (m == n)
{
printf("m and n are equal");
}
else
{
printf("m and n are not equal");
}
return 0;
}
Example showing use
Operator

of Logical
#include <stdio.h>
int main()
{
int m=40,n=20;
int a=20,p=30;
if (m>n && m !=0)
{ printf("&& Operator : Both conditions are truen"); }
if (a>p || p!=20)
{ printf("|| Operator : Only one condition is truen"); }
if (!(m>n && m !=0))
{
else
printf("! Operator : Both conditions are truen"); }
{ printf("! Operator : Both conditions are true. " 
"But, status is inverted as falsen");
}
return 0;
}
BIT WISE OPERATORS IN C

 These operators are used to perform bit operations.
Decimal values are converted into binary values
which are the sequence of bits and bit wise operators
work on these bits. Following are bitwise operator
1)
2)
3)
4)
5)
6)
&
|
~
^
<<
>>
Bitwise AND
Bitwise OR
Bitwise NOT
XOR
Left Shift
Right Shift
Program showing Bitwise Operator

in C
#include <stdio.h>
int main()
{
int m = 40,n = 80,AND_opr,OR_opr,XOR_opr,NOT_opr ;
AND_opr = (m&n);
OR_opr = (m|n);
NOT_opr = (~m);
XOR_opr = (m^n);
printf("AND_opr value = %dn",AND_opr );
printf("OR_opr value = %dn",OR_opr );
printf("NOT_opr value = %dn",NOT_opr );
printf("XOR_opr value = %dn",XOR_opr );
printf("left_shift value = %dn", m << 1);
printf("right_shift value = %dn", m >> 1);
}
CONDITIONAL OR TERNARY
OPERATORS IN C

 Conditional operators return one value if condition
is true and returns another value is condition is false.
 This operator is also called as ternary operator.
Syntax
Example
:
:
(Condition? true_value: false_value);
(A > 100 ? 0 : 1);
Program for use of Ternary

Operator
#include <stdio.h>
int main()
{
int x=1, y ;
y = ( x ==1 ? 2 : 0 ) ;
printf("x value is %dn", x);
printf("y value is %d", y);
return 0;
}
Increment / Decrement
Operators

 Increment operators are used to increase the value of
the variable by one and decrement operators are
used to decrease the value of the
programs.
Increment operator
variable by one in C
++var_name; (or) var_name++;
Decrement operator
- -var_name; (or) var_name – -;
Example for increment

operators
#include <stdio.h>
int main()
{
int i=1;
while(i<10)
{
printf("%d
i++;
",i);
}
return 0;
}
Example for Decrement

operators
#include <stdio.h>
int main()
{
int i=1;
while(i<10)
{
printf("%d
i--;
",i);
}
return 0;
}
Exercises
Arithmetic Operators
i. Write a program to determine whether a number is divisible
by 5 or not
ii. Write a program to determine if a number is even or odd
iii. Write a C program to check whether a given number is
positive or negative
Relational Operators
i. Write a program to give a discount of 10% if amount of items
purchased exceeds Sh5000
Exercise - Logical operators
i. Write a program to check if a person is eligible to vote. The person
must be a Kenyan Citizen and above 18 years
ii. Write a program to implement the following requirements.
Requirement
A bank will offer a customer a loan if they are 21 or over and have an
annual income of at least Sh21,000. The customers age and income are
input in response to user friendly prompts. Write a program that will
output the following
Expected output
• Congratulations you qualify for a loan.
• Unfortunately, we are unable to offer you a loan at this time .


More Related Content

Similar to Types of Operators in C programming .pdf

C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdfMaryJacob24
 
Introduction to C programming language. Coding
Introduction to C programming language. CodingIntroduction to C programming language. Coding
Introduction to C programming language. CodingTanishqGosavi
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3rohassanie
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
Operators-computer programming and utilzation
Operators-computer programming and utilzationOperators-computer programming and utilzation
Operators-computer programming and utilzationKaushal Patel
 
Project in TLE
Project in TLEProject in TLE
Project in TLEPGT_13
 
Report Group 4 Constants and Variables
Report Group 4 Constants and VariablesReport Group 4 Constants and Variables
Report Group 4 Constants and VariablesGenard Briane Ancero
 
Report Group 4 Constants and Variables(TLE)
Report Group 4 Constants and Variables(TLE)Report Group 4 Constants and Variables(TLE)
Report Group 4 Constants and Variables(TLE)Genard Briane Ancero
 
C Operators and Control Structures.pptx
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptxramanathan2006
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptxManojKhadilkar1
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2Don Dooley
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in cSaranya saran
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c languageTanmay Modi
 
C language operator
C language operatorC language operator
C language operatorcprogram
 

Similar to Types of Operators in C programming .pdf (20)

C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 
operators.pptx
operators.pptxoperators.pptx
operators.pptx
 
Introduction to C programming language. Coding
Introduction to C programming language. CodingIntroduction to C programming language. Coding
Introduction to C programming language. Coding
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Operators-computer programming and utilzation
Operators-computer programming and utilzationOperators-computer programming and utilzation
Operators-computer programming and utilzation
 
Project in TLE
Project in TLEProject in TLE
Project in TLE
 
Report Group 4 Constants and Variables
Report Group 4 Constants and VariablesReport Group 4 Constants and Variables
Report Group 4 Constants and Variables
 
Report Group 4 Constants and Variables(TLE)
Report Group 4 Constants and Variables(TLE)Report Group 4 Constants and Variables(TLE)
Report Group 4 Constants and Variables(TLE)
 
C Operators and Control Structures.pptx
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptx
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
Theory3
Theory3Theory3
Theory3
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Unit 4 (1)
Unit 4 (1)Unit 4 (1)
Unit 4 (1)
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
2. operator
2. operator2. operator
2. operator
 
C language operator
C language operatorC language operator
C language operator
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Types of Operators in C programming .pdf

  • 2.
  • 4. Arithmetic Operators Operator Name Description Example + Addition Adds together two values x + y - Subtraction Subtracts one value from another x - y * Multiplication Multiplies two values x * y / Division Divides one value by another x / y % Modulus Returns the division remainder x % y ++ Increment Increases the value of a variable by 1 ++x -- Decrement Decreases the value of a variable by 1 --x
  • 5. #include<stdio.h> int main() { int a, b, add, sub, mul, div, rem; printf("Enter a, b values : "); scanf("%d%d",&a,&b); // Reading two values add=a+b; // Addition Operator sub=a-b; // Subtraction Operator mul=a*b; // Multiplication Operator div=a/b; // Division Operator rem=a%b; // Remainder (Modulo) Operator printf("Result of addition is=%dn", add); printf("Result of subtraction=%dn", sub); printf("Result of multiplication is=%dn", mul); printf("Result of division is=%dn", div); printf("Result of remainder=%dn",rem); return 0; }
  • 6. Assignment Operators Operator Example Same As = x = 5 x = 5 += x += 3 x = x + 3 -= x -= 3 x = x - 3 *= x *= 3 x = x * 3 /= x /= 3 x = x / 3 %= x %= 3 x = x % 3 &= x &= 3 x = x & 3 |= x |= 3 x = x | 3 ^= x ^= 3 x = x ^ 3 >>= x >>= 3 x = x >> 3 <<= x <<= 3 x = x << 3 Assignment operators are used to assign values to variables.
  • 7. Comparison Operators • Comparison operators are used to compare two values (or variables) Operator Name Example == Equal to x == y != Not equal x != y > Greater than x > y < Less than x < y >= Greater than or equal to x >= y <= Less than or equal to x <= y
  • 8. Logical Operators • Used to determine the logic between variables or values Operator Name Description Example && Logical and Returns true if both statements are true x < 5 && x < 10 || Logical or Returns true if one of the statements is true x < 5 || x < 4 ! Logical not Reverse the result, returns false if the result is true !(x < 5 && x < 10)
  • 10. Use of sizeof() operator
  • 11. Example showing use Operator  of Relational #include <stdio.h> int main() { int m=40,n=20; if (m == n) { printf("m and n are equal"); } else { printf("m and n are not equal"); } return 0; }
  • 12. Example showing use Operator  of Logical #include <stdio.h> int main() { int m=40,n=20; int a=20,p=30; if (m>n && m !=0) { printf("&& Operator : Both conditions are truen"); } if (a>p || p!=20) { printf("|| Operator : Only one condition is truen"); } if (!(m>n && m !=0)) { else printf("! Operator : Both conditions are truen"); } { printf("! Operator : Both conditions are true. " "But, status is inverted as falsen"); } return 0; }
  • 13. BIT WISE OPERATORS IN C   These operators are used to perform bit operations. Decimal values are converted into binary values which are the sequence of bits and bit wise operators work on these bits. Following are bitwise operator 1) 2) 3) 4) 5) 6) & | ~ ^ << >> Bitwise AND Bitwise OR Bitwise NOT XOR Left Shift Right Shift
  • 14. Program showing Bitwise Operator  in C #include <stdio.h> int main() { int m = 40,n = 80,AND_opr,OR_opr,XOR_opr,NOT_opr ; AND_opr = (m&n); OR_opr = (m|n); NOT_opr = (~m); XOR_opr = (m^n); printf("AND_opr value = %dn",AND_opr ); printf("OR_opr value = %dn",OR_opr ); printf("NOT_opr value = %dn",NOT_opr ); printf("XOR_opr value = %dn",XOR_opr ); printf("left_shift value = %dn", m << 1); printf("right_shift value = %dn", m >> 1); }
  • 15. CONDITIONAL OR TERNARY OPERATORS IN C   Conditional operators return one value if condition is true and returns another value is condition is false.  This operator is also called as ternary operator. Syntax Example : : (Condition? true_value: false_value); (A > 100 ? 0 : 1);
  • 16. Program for use of Ternary  Operator #include <stdio.h> int main() { int x=1, y ; y = ( x ==1 ? 2 : 0 ) ; printf("x value is %dn", x); printf("y value is %d", y); return 0; }
  • 17. Increment / Decrement Operators   Increment operators are used to increase the value of the variable by one and decrement operators are used to decrease the value of the programs. Increment operator variable by one in C ++var_name; (or) var_name++; Decrement operator - -var_name; (or) var_name – -;
  • 18. Example for increment  operators #include <stdio.h> int main() { int i=1; while(i<10) { printf("%d i++; ",i); } return 0; }
  • 19. Example for Decrement  operators #include <stdio.h> int main() { int i=1; while(i<10) { printf("%d i--; ",i); } return 0; }
  • 20. Exercises Arithmetic Operators i. Write a program to determine whether a number is divisible by 5 or not ii. Write a program to determine if a number is even or odd iii. Write a C program to check whether a given number is positive or negative Relational Operators i. Write a program to give a discount of 10% if amount of items purchased exceeds Sh5000
  • 21. Exercise - Logical operators i. Write a program to check if a person is eligible to vote. The person must be a Kenyan Citizen and above 18 years ii. Write a program to implement the following requirements. Requirement A bank will offer a customer a loan if they are 21 or over and have an annual income of at least Sh21,000. The customers age and income are input in response to user friendly prompts. Write a program that will output the following Expected output • Congratulations you qualify for a loan. • Unfortunately, we are unable to offer you a loan at this time .
  • 22.