Conditionl Logic & Operator:
Conditionl
Logic used to write a program.It is most important in C programming. Conditionl
Logic is used by some operators. 
- Such as,Arithmetic operator.Five arithmetic operator are used in C.They are :
 
                     + ⟶Addition
                 - ⟶Subtraction
                * ⟶Multiplication
                 / ⟶Division
               %⟶Remainder after
integer division
For example in C,
#include<stdio.h>
int main( )
{
int a=20,b=5,c;
c=a+b;
printf("%d",c);
}
       The  output of this program is 25
Other arithmetic operators  are work in same ways. 
- Another operator is Unary operator.There are two other commonly used unary operators.The increment(++) operator & the decrement (--) operator.Increment means ,value increased by 1.Decrement means, value decreased by 1.
 
For example,
#include<stdio.h>
int main( )
{
int a=20;
a++;
printf("%d",a);
}
a++  means,
                   a=a+1
so the output is  21
And  a-- 
means,
                    a=a-1
- Another operator is Relational operator ,which is used in conditional logic.There are 6 relational operator in C.They are,
 
Operator                       Meaning
     >                               greater  than
     >=                             greater  than 
or  equal  to
     <                               less than
     <=                             less than  or 
equal  to
     ==                             equal  to
     !=                              not  equal 
to
For  example,
#include<stdio.h>
int main( )
{
int a=20,b=5;
if(a>=b)
{
                                  printf("True");
                              }
                            else
                             {
    Printf("False");
          }
}
The
output is  True
Because
a=20 which is greater than b=5
The
condition of if(a>=b)  is true.So compiler check the statement in if condition and print this statement.And compiler
check else condition when if condition is false….
- Another is Assignment operator.Which is,
 
Identifier = expression
Identifier means variable & expression means constant/value.
Such
as,
                   a=3
                    b=c
                   sum=a+b
These
are assignment operator.Here 3 assigned to the variable a, c assigned to b and
so on..
Remember
that, assignment(=) and equality(==) 
operator are distinctly different.Assignment operator means assign value
but equality operator means the same value between two expressions.
- If ,else condition are used in conditional logic.Wherever if condition is true then this program print statement of if.Otherwise print statement of else. We can clear this by following program:
 
 In this
code, if  a=20,b=10  then (20>10) which is true.And  compiler check the if statement.Store  c=20+10=30  .Print 
30
But when input a=10,b=20 then (10>20) which is false .And compiler check else statement .Then print 10 

Informative
ReplyDeletethanks
ReplyDelete