How can a computer performs mathematics ? It is the arithmetic operators !

Welcome back to the Newbie Programmer Series. In the last post we have learned what are relational operators and how to use them wisely. The most important thing that they gives zeros and ones as answers and not do any numerical calculations. If they find the relation true, the 1 otherwise 0.

In this part, we will learn what are the logical operators and their use within coding. If you are new to this series, please go to the index ( click here ) and check out all the previous parts so that you can easily understand what I am talking about here.

Also for this one, I have written a special article : Inside Logic Gates, The electronic logic. Before going further, you must go to that link to learn how logic actually works with electronic devices.

## The Need of logic. Connecting Relations

- Above 13 years of age
- Less than 35 years of age
- Unmarried
- Not your sisters
- Either of Science Teacher or Maths Teacher ( not both )

```
SEND EMAIL TO:
(age > 13) AND (age < 35)
NOT { (married) AND (sisters) }
(science teacher) OR (maths teacher)
```

## Adding logic to code

Unlike the arithmetic operators, Logical operators DO NOT give any answers. They just check and give 1 for TRUE and 0 for FALSE.

*(relational operation)*

**LOGICAL OPERATOR**

*(relational operation).*

#### AND " && "

**1 && 1 TRUE, all other FALSE**

#### OR " || "

**0 || 0 FALSE, all other TRUE**

#### NOT " ! "

**!(1) FALSE , !(0) TRUE**

### Example:

```
#include <stdio.h>
main()
{
printf("logic checker \n");
//change the value of variables
int A = 1;
int B = 2;
while (( A < B ) && ( A < 10)) //change everything
{
printf("It is correct ! \n");
return(0); //to exit
}
printf("Not correct \n");
return(0); //to exit
}
```

How to use it ? Simple. Change the value of the variables as you want. Change the operator in the while loop to that one you want to check. If the logic between the relations you have set is TRUE, the while loop will work and you will get printed "It is correct !" and then the program will exit. If the logic is NOT TRUE, the while loop will be skipped. You will get printed "Not Correct" and the program will exit.
That's it for today. You can make your own programs and then send me. I will post your programs for you. Play more with the above operators. I will meet you in the next post with other Operators !
Stay Connected.
Please share this post as much as you can so that we can get connected to more geeks who wants to learn programming but have no clue. Thanks for reading :) (c)Shubham Ramdeo, All rights reserved.

Please share this as much as you can so that we can get connected with more and more people who want to learn programming.