Logical Operator


Write a C Program by using Logical AND and OR Operator

 

Logical Operators

Statement of C Program: This Program illustrates the logical AND and OR operations: 

#include<stdio.h>
#include<conio.h>
void main()
{
int a , b , c;
clrscr();
a = 4 , b = 3;

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

Output:
1
1
1


Example program for logical operators in C:

Output:

&& Operator : Both conditions are true
|| Operator : Only one condition is true
! Operator : Both conditions are true. But, status is inverted as false

5 comments:

  1. //Write a C Program by using Logical OR

    #include
    main()
    {
    int a,b,c;

    scanf("%d%d",&a,&b);

    c=a>10||b>10;

    printf("%d",c);

    }

    ReplyDelete
  2. //Write a C Program by using Logical AND

    #include
    main()
    {
    int a,b,c;

    scanf("%d%d",&a,&b);

    c=a>10&&b>10;

    printf("%d",c);

    }

    ReplyDelete
  3. #include
    #include
    void main()
    {
    int i , j , k;
    clrscr();
    i = 4 , j = 3;

    k = i && j;
    j = i|| j || k;
    i = j && j || k;
    printf("%d" , i\n);
    printf("%d" , j\n);
    printf("%d" , k\n);
    }

    ReplyDelete
  4. #include
    #include
    void main()
    {
    int i , j , k;
    clrscr();
    i = 4 , j = 3;

    k = i && j;
    j = i|| j || k;
    i = j && j || k;
    printf("%d" , i\n);
    printf("%d" , j\n);
    printf("%d" , k\n);
    }

    ReplyDelete
  5. #include
    #include
    void main()
    {
    int i , j , k;
    clrscr();
    i = 4 , j = 3;

    k = i && j;
    j = i|| j || k;
    i = j && j || k;
    printf("%d" , i\n);
    printf("%d" , j\n);
    printf("%d" , k\n);
    }

    ReplyDelete