2. INTRODUCTION TO COMPUTER PROGRAMMING
1) Operators, Arithmetic and Arithmetic assignment operators.
2) Increment Operator, Decrement Operator.
3) Relational Operator.
3. Operators
• Operators are words or symbols that cause a program to do
something to variables.
• For example, the arithmetic operators (+) and (-) cause a
program to add or subtract two numbers.
Many different kind of operators
• + Addition
• - Subtraction
• * Multiplication
• / Division
• % Remainder
4. Fahrenheit to Celsius Temperature conversion
#include<stdio.h>
void main(void)
{
int ftemp,ctemp;
pritnf((“Type temperature in degree fahrenheit”);
scanf((“%d”,&ftemp);
ctemp=(ftemp-32)*5/9;
printf(“Temperature in degree Celsius is %d”,ctemp);
}
5. Celsius to Fahrenheit Temperature conversion
#include<stdio.h>
void main(void)
{
int ftemp,ctemp;
pritnf((“Type temperature in degree fahrenheit”);
printf(“Temperature in degree Celsius is %d”,ctemp);
}
6. Operator Precedence
• We have parenthesis around f(temp-32) known as precedence.
• The fact (*) abd (/) are evaluated before(+) and(-).
• We say that (*) and (/) has higher precedence than (+) and (-).
Remainder Operator
• Remainder operator(sometimes called modulor operator)
may be unfamiliar to you.
• It is used to find remainder when one number is divided by
another
• For example answer=13%5
value is 3
8. Arithmetic Assignment Operator
Syntax:
Arithmetic op=
• += (Addition Assignment Operator)
• -= (Subtraction Assignment Operator)
• *= (Multiplication Assignment Operator)
• /= (Division Assignment Operator)
• %= (Remainder Assignment Operator)
• a+=1 is same as=> a=a+1
• a-=1 is same as=> a=a-1
• a*=1 is same as=> a=a*1
• a/=1 is same as=> a=a/1
• a%=1 is same as a=a%1
9. Increment Operator
+=,-=,++,--
+=(Addition Assignment Operator)
It is also known as increment operator
Syntax:
variable+=value;
variable=variable+value
-=(Subtraction Assignment Operator)
It is also known as increment operator
Syntax:
Variable-=value;
variable=variable-value
10. • Postfix increment and Postfix decrement Operator
• Prefix increment and Prefix decrement Operator
Op++
• It is postfix increment operator
++Op
• It is prefix increment operator
Op--
• It is postfix decrement operator
--Op
• It is prefix decrement operator
11. variable++ as postfix increment operator
#include<stdio.h>
void main(void)
{
int num=0;
printf(“Number=%dn”,num);
printf(“Number=%dn”,num++);
printf(“Number=%dn”,num);
}
12. ++variable as prefix increment operator
#include<stdio.h>
void main(void)
{
int num=0;
printf(“Number=%dn”,num);
printf(“Number=%dn”,++num);
printf(“Number=%dn”,num);
}
13. variable-- as Postfix decrement operator
#include<stdio.h>
void main(void)
{
int num=0;
printf(“Number=%dn”,num);
printf(“Number=%dn”,num--);
printf(“Number=%dn”,num);
}
14. --variable as Prefix decrement operator
#include<stdio.h>
void main(void)
{
int num=0;
printf(“Number=%dn”,num);
printf(“Number=%dn”,--num);
printf(“Number=%dn”,num);
}
15. Relational Operators
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to
&& Logical AND or short circuit AND
|| Logical OR or short circuit OR