3 Operators, Function, Algorithm and Flowchart
3 Operators, Function, Algorithm and Flowchart
Function
Algorithm
Flowchart
Introduction
An operator is a symbol that tells the computer to perform
certain mathematical or logical manipulations. Operators are
used in programs to manipulate data and variables.
C operators can be classified into a number of categories.
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Increment and decrement operators
Conditional operators
Bitwise operators
Special operators
Relational Operators
• The relational operators in C are :
Used to compare values of two expressions
depending on their relations.
Operator Meaning
< less that
<= less than or equal to
> greater than
>= greater than or equal to
== equal to
!= not equal to
Relational Operators
5 < 6 TRUE 1
4.5<10 TRUE 1
-34 + 8 > 23 - 5 FALSE 0
4.5<-10 FALSE 0
5==0 FALSE 0
Arithmetic operators have higher priority over relational
operators.
the associativity of relational operators is left right
Relational Operators
3 >= 2 = = -4 < 0
Operator
An operator is a symbol that tells the computer to perform
certain mathematical or logical manipulations. Operators are
used in programs to manipulate data and variables.
C operators can be classified into a number of categories.
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Increment and decrement operators
Conditional operators
Bitwise operators
Special operators
Logical operators
C has the following three logical operators
&& meaning logical AND ( binary operator )
|| meaning logical OR ( binary operator )
! meaning logical NOT( unary operator )
a = a+1 a += 1
a = a-1 a -= 1
a = a * (n+1) a *= n+1
a = a / (n+1) a /= n+1
a=a%b a %= b
Assignment operators
The use of shorthand assignment operators
has three advantages:
#include<math.h>
Mathematical functions
for example
the roots of ax2+bx+c =0 are
x b b 4 ac
2
2a
x1= ( -b + sqrt ( b*b - 4*a*c ) ) / ( 2 * a )
x2= ( -b – sqrt ( b*b - 4*a*c ) ) / ( 2 * a )
Solution of the quadratic equation
#include<stdio.h>
#include<math.h>
main()
{
float a,b,c,discriminant,root1,root2;
printf("Input values of a,b, and c\n");
scanf("%f %f %f",&a,&b,&c);
discriminant= b*b-4*a*c;
if(discriminant<0)
printf("\n\nRoots are imaginary\n");
else
{
root1=(-b+sqrt(discriminant))/(2.0*a);
root2=(-b-sqrt(discriminant))/(2*a);
printf("\n\nRoot1=%5.2f\n\nRoots=%5.2f\n",root1,root2);
}
}