In diesem Abschnitt wird der logische NOT-Operator (!) in der Programmiersprache C besprochen. Wie wir bereits wissen, wird der logische Operator verwendet, um die logische Operation durch die Kombination von zwei oder mehr Bedingungen für die gegebenen Ausdrücke auszuführen. Wenn die logischen Bedingungen der Operanden wahr sind, gibt der Operator wahre boolesche Werte oder 1 zurück. Andernfalls gibt er einen falschen booleschen Wert oder 0 zurück. Die logischen Operatoren werden in drei Teile eingeteilt: Logische UND-, logische ODER- und logische NICHT-Operatoren.
Der logischer UND-Operator wird verwendet, um zu überprüfen, ob die Bedingungen von zwei oder mehr verbleibenden Operanden in einem bestimmten Ausdruck wahr sind; Der AND-Operator gibt einen wahren Wert oder einen Wert ungleich Null (1) zurück. Andernfalls wird ein falscher oder 0-Wert zurückgegeben. Wir können also sagen, dass der logische UND-Operator nur dann in einem Ausdruck ausgeführt werden kann, wenn die Bedingungen beider Operanden wahr sind, und wenn eine Bedingung nicht wahr ist, wird 0 zurückgegeben. Der logische UND-Operator wird als doppeltes kaufmännisches Und-Symbol „&&“ dargestellt.
Syntax:
(A > b && b > c)
Der logischer ODER-Operator wird verwendet, um die Bedingungen beider Operanden (A und B) zu überprüfen. Wenn einer der Operanden oder Ausdrücke wahr ist, gibt der Operator einen wahren booleschen Wert zurück. Wenn keiner der Ausdrücke wahr ist, wird ein falscher oder Nullwert zurückgegeben. Der logische ODER-Operator wird als Doppelpipe „||“ bezeichnet. Symbol.
MVC im Spring Framework
Syntax:
(A > B) || (A <c) < pre> <h3>Logical NOT operator</h3> <p>The logical NOT operator is represented as the '!' symbol, which is used to reverse the result of any given expression or condition. If the result of an expression is non-zero or true, the result will be reversed as zero or false value. Similarly, if the condition's result is false or 0, the NOT operator reverses the result and returns 1 or true.</p> <p>For example, suppose the user enters a non-zero value is 5, the logical NOT (!) operator returns the 0 or false Boolean value. And if the user enters a zero (0) value, the operator returns the true Boolean value or 1. </p> <p> <strong>Syntax of the logical NOT operator</strong> </p> <pre> ! (condition); // It '!' represents the NOT operator </pre> <p>Here, the '!' symbol represents the logical NOT operator, which inverses the result of the given condition.</p> <h3>The truth table of the logical NOT operator:</h3> <p>Following is the truth table of the logical not operator in C</p> <pre> condition !(condition) 1 0 0 1 </pre> <h3>Example 1: Program to use the logical NOT operator in C</h3> <p>Let's create a simple program to reverse the given condition of the operands in the C programming language.</p> <pre> /* demonstration the use of the logical not operator in C. */ #include #include int main () { // declare an initialize x variable int x = 5; // display the result generated using the NOT (!) operator printf (' The return value = %d ', ! (x == 5)); printf (' The return value = %d ', ! (x != 5)); printf (' The return value = %d ', ! (x >= 3)); printf (' The return value = %d ', ! (x <3)); return 0; } < pre> <p> <strong>Output:</strong> </p> <pre> The return value = 0 The return value = 1 The return value = 0 The return value = 1 </pre> <p>In the above program, we use the NOT (!) operator to reverse the result of the various expression, such as the condition of the variable x is equal to 5, which is true. Still, the NOT operator reverses the result and returns 0. Similarly, we defined the condition (x!=5), but the logical operator changed its result and returned 1 and so on.</p> <h3>Example 2: Program to input a number to perform the logical NOT operator</h3> <p>Let's create a simple program to get the reverse result of an integer number using the logical NOT (!) operator in the C programming language.</p> <pre> /* demonstration the use of the logical not operator in C. */ #include #include int main () { // declare an initialize x variable int x, n; printf (' Enter the number: '); scanf ('%d', &x); n = !x; // use logical not operator to reverse the condition printf (' The result of x: %d', n); // display the result return 0; } </pre> <p> <strong>Output:</strong> </p> <pre> Enter the number: 7 The result of x: 0 </pre> <p>In the above program, we input an integer number 7 from the user and store it into x variable. After that, the logical NOT (!) operator reverses the value of x (non-zero) and returns zero (0) to print the result of x.</p> <p> <strong>2<sup>nd</sup> execution:</strong> </p> <pre> Enter the number: 0 The result of x: 1 </pre> <p>Similarly, we input zero (0) from the user and use the logical NOT (!) operator to reverse the value of x to a non-zero value, which is 1.</p> <h3>Example 3: Program to find the leap year using the logical AND (&&), OR (||), and NOT (!) operator</h3> <p>Let's write a simple program to check whether the given year is a leap or not using the logical AND (&&), logical OR (||), and the logical NOT (!) operator in the C language.</p> <pre> #include #include int main () { int yr; // declare int type variable printf (' Enter the year: '); scanf ('%d', &yr); // use the if..else statement to check the condition /* '&&' (AND) operator to validate both operand, '||' (OR) operator check ny given expressions are true, '!' (NOT) check the result of (yr % 100 != 0). */ if ( (yr % 400 == 0) || (yr % 4 == 0 && yr % 100 != 0)) { printf (' %d is a leap year. ', yr); } else { printf (' %d is not a leap year. ', yr); } return 0; } </pre> <p> <strong>Output:</strong> </p> <pre> Enter the year: 2020 2020 is a leap year. </pre> <p>In the above program, we enter 2020 and then check the given year by defining the if...else statement. In this statement, we defined two conditions;</p> <ol class="points"> <li>The given year is divided by 400, which is equal to 0. And then, we use the logical OR operator to check whether the left or right operand condition is true.</li> <li>In the second condition, the given year is divided by 4 and 100. But when we divide 2020 with 4, which is equal to 0. Similarly, we divide the year 2020 by 100, which is also not equal to 0. So, both the conditions are true that display the '2020 is a leap year'.</li> <li>But when we enter the year 2021, it prints the given result '2021 is not a leap year'.</li> </ol> <p> <strong>2<sup>nd</sup> execution:</strong> </p> <pre> Enter the year: 2021 2021 is not a leap year. </pre> <p> <strong>Example 4: Program to check different conditions using the AND, OR, and the NOT logical operator</strong> </p> <p>Let's write a program to demonstrate the multiple conditions of the given operands using the AND, OR, and the NOT logical operator in C.</p> <pre> /* program to check the various condition using the logical NOT operator in c. */ #include #include int main () { // declare and initialize variables int a = 20, b = 15; int n1 = 15, n2 = 17; // use logical 'AND' and logical 'NOT' operator if (a > b && a != 0) { printf (' The AND (&&) operator said: Both conditions are true. '); } // use logical 'OR' and logical 'NOT' operator if (n1 > n2 || n2 != 15) if ( ! (a > b && a != 0 )) { printf (' The NOT (!) operator: Here both conditions are true. '); } else { printf (' The NOT (!) operator: Here, both conditions are true. ' ' But, the status of the condition is reversed as false. '); } return 0; } </pre> <p> <strong>Output:</strong> </p> <pre> The AND (&&) operator is said: Both conditions are true. The OR (||) operator is said: Only one condition is true. The NOT (!) operator: Here, both conditions are true. But, the status of the condition is reversed as false. </pre> <hr></3));></pre></c)>
Hier das '!' Das Symbol stellt den logischen NOT-Operator dar, der das Ergebnis der gegebenen Bedingung umkehrt.
Die Wahrheitstabelle des logischen NOT-Operators:
Es folgt die Wahrheitstabelle des logischen Nicht-Operators in C
condition !(condition) 1 0 0 1
Beispiel 1: Programm zur Verwendung des logischen NOT-Operators in C
Lassen Sie uns ein einfaches Programm erstellen, um die gegebene Bedingung der Operanden in der Programmiersprache C umzukehren.
/* demonstration the use of the logical not operator in C. */ #include #include int main () { // declare an initialize x variable int x = 5; // display the result generated using the NOT (!) operator printf (' The return value = %d ', ! (x == 5)); printf (' The return value = %d ', ! (x != 5)); printf (' The return value = %d ', ! (x >= 3)); printf (' The return value = %d ', ! (x <3)); return 0; } < pre> <p> <strong>Output:</strong> </p> <pre> The return value = 0 The return value = 1 The return value = 0 The return value = 1 </pre> <p>In the above program, we use the NOT (!) operator to reverse the result of the various expression, such as the condition of the variable x is equal to 5, which is true. Still, the NOT operator reverses the result and returns 0. Similarly, we defined the condition (x!=5), but the logical operator changed its result and returned 1 and so on.</p> <h3>Example 2: Program to input a number to perform the logical NOT operator</h3> <p>Let's create a simple program to get the reverse result of an integer number using the logical NOT (!) operator in the C programming language.</p> <pre> /* demonstration the use of the logical not operator in C. */ #include #include int main () { // declare an initialize x variable int x, n; printf (' Enter the number: '); scanf ('%d', &x); n = !x; // use logical not operator to reverse the condition printf (' The result of x: %d', n); // display the result return 0; } </pre> <p> <strong>Output:</strong> </p> <pre> Enter the number: 7 The result of x: 0 </pre> <p>In the above program, we input an integer number 7 from the user and store it into x variable. After that, the logical NOT (!) operator reverses the value of x (non-zero) and returns zero (0) to print the result of x.</p> <p> <strong>2<sup>nd</sup> execution:</strong> </p> <pre> Enter the number: 0 The result of x: 1 </pre> <p>Similarly, we input zero (0) from the user and use the logical NOT (!) operator to reverse the value of x to a non-zero value, which is 1.</p> <h3>Example 3: Program to find the leap year using the logical AND (&&), OR (||), and NOT (!) operator</h3> <p>Let's write a simple program to check whether the given year is a leap or not using the logical AND (&&), logical OR (||), and the logical NOT (!) operator in the C language.</p> <pre> #include #include int main () { int yr; // declare int type variable printf (' Enter the year: '); scanf ('%d', &yr); // use the if..else statement to check the condition /* '&&' (AND) operator to validate both operand, '||' (OR) operator check ny given expressions are true, '!' (NOT) check the result of (yr % 100 != 0). */ if ( (yr % 400 == 0) || (yr % 4 == 0 && yr % 100 != 0)) { printf (' %d is a leap year. ', yr); } else { printf (' %d is not a leap year. ', yr); } return 0; } </pre> <p> <strong>Output:</strong> </p> <pre> Enter the year: 2020 2020 is a leap year. </pre> <p>In the above program, we enter 2020 and then check the given year by defining the if...else statement. In this statement, we defined two conditions;</p> <ol class="points"> <li>The given year is divided by 400, which is equal to 0. And then, we use the logical OR operator to check whether the left or right operand condition is true.</li> <li>In the second condition, the given year is divided by 4 and 100. But when we divide 2020 with 4, which is equal to 0. Similarly, we divide the year 2020 by 100, which is also not equal to 0. So, both the conditions are true that display the '2020 is a leap year'.</li> <li>But when we enter the year 2021, it prints the given result '2021 is not a leap year'.</li> </ol> <p> <strong>2<sup>nd</sup> execution:</strong> </p> <pre> Enter the year: 2021 2021 is not a leap year. </pre> <p> <strong>Example 4: Program to check different conditions using the AND, OR, and the NOT logical operator</strong> </p> <p>Let's write a program to demonstrate the multiple conditions of the given operands using the AND, OR, and the NOT logical operator in C.</p> <pre> /* program to check the various condition using the logical NOT operator in c. */ #include #include int main () { // declare and initialize variables int a = 20, b = 15; int n1 = 15, n2 = 17; // use logical 'AND' and logical 'NOT' operator if (a > b && a != 0) { printf (' The AND (&&) operator said: Both conditions are true. '); } // use logical 'OR' and logical 'NOT' operator if (n1 > n2 || n2 != 15) if ( ! (a > b && a != 0 )) { printf (' The NOT (!) operator: Here both conditions are true. '); } else { printf (' The NOT (!) operator: Here, both conditions are true. ' ' But, the status of the condition is reversed as false. '); } return 0; } </pre> <p> <strong>Output:</strong> </p> <pre> The AND (&&) operator is said: Both conditions are true. The OR (||) operator is said: Only one condition is true. The NOT (!) operator: Here, both conditions are true. But, the status of the condition is reversed as false. </pre> <hr></3));>
Im obigen Programm verwenden wir den NOT-Operator (!), um das Ergebnis verschiedener Ausdrücke umzukehren, z. B. wenn die Bedingung der Variablen x gleich 5 ist, was wahr ist. Dennoch kehrt der NOT-Operator das Ergebnis um und gibt 0 zurück. Ebenso haben wir die Bedingung (x!=5) definiert, aber der logische Operator hat sein Ergebnis geändert und 1 zurückgegeben und so weiter.
Beispiel 2: Programm zur Eingabe einer Zahl zur Ausführung des logischen NOT-Operators
Lassen Sie uns ein einfaches Programm erstellen, um das umgekehrte Ergebnis einer Ganzzahl zu erhalten, indem wir den logischen Operator NOT (!) in der Programmiersprache C verwenden.
Größe des Vektors c++
/* demonstration the use of the logical not operator in C. */ #include #include int main () { // declare an initialize x variable int x, n; printf (' Enter the number: '); scanf ('%d', &x); n = !x; // use logical not operator to reverse the condition printf (' The result of x: %d', n); // display the result return 0; }
Ausgabe:
Enter the number: 7 The result of x: 0
Im obigen Programm geben wir vom Benutzer eine Ganzzahl 7 ein und speichern sie in der Variablen x. Danach kehrt der logische NOT-Operator (!) den Wert von x (ungleich Null) um und gibt Null (0) zurück, um das Ergebnis von x auszugeben.
2ndAusführung:
Enter the number: 0 The result of x: 1
In ähnlicher Weise geben wir vom Benutzer Null (0) ein und verwenden den logischen NOT-Operator (!), um den Wert von x in einen Wert ungleich Null umzukehren, der 1 ist.
Beispiel 3: Programm zum Ermitteln des Schaltjahres mithilfe der logischen Operatoren AND (&&), OR (||) und NOT (!)
Schreiben wir ein einfaches Programm, um mithilfe des logischen UND (&&), des logischen ODER (||) und des logischen NICHT-Operators (!) in der Sprache C zu prüfen, ob das angegebene Jahr ein Sprungjahr ist oder nicht.
So finden Sie versteckte Dinge auf Android
#include #include int main () { int yr; // declare int type variable printf (' Enter the year: '); scanf ('%d', &yr); // use the if..else statement to check the condition /* '&&' (AND) operator to validate both operand, '||' (OR) operator check ny given expressions are true, '!' (NOT) check the result of (yr % 100 != 0). */ if ( (yr % 400 == 0) || (yr % 4 == 0 && yr % 100 != 0)) { printf (' %d is a leap year. ', yr); } else { printf (' %d is not a leap year. ', yr); } return 0; }
Ausgabe:
Enter the year: 2020 2020 is a leap year.
Im obigen Programm geben wir 2020 ein und überprüfen dann das angegebene Jahr, indem wir die if...else-Anweisung definieren. In dieser Erklärung haben wir zwei Bedingungen definiert;
- Das angegebene Jahr wird durch 400 geteilt, was gleich 0 ist. Anschließend verwenden wir den logischen ODER-Operator, um zu prüfen, ob die linke oder rechte Operandenbedingung wahr ist.
- In der zweiten Bedingung wird das gegebene Jahr durch 4 und 100 geteilt. Aber wenn wir 2020 durch 4 teilen, ist das gleich 0. Ebenso teilen wir das Jahr 2020 durch 100, was ebenfalls ungleich 0 ist. Also beides Die Bedingungen sind wahr, die anzeigen, dass „2020 ein Schaltjahr ist“.
- Wenn wir jedoch das Jahr 2021 eingeben, wird das angegebene Ergebnis ausgegeben: „2021 ist kein Schaltjahr“.
2ndAusführung:
Enter the year: 2021 2021 is not a leap year.
Beispiel 4: Programm zur Prüfung verschiedener Bedingungen mithilfe der logischen Operatoren AND, OR und NOT
Java-Liste zum Array
Schreiben wir ein Programm, um die mehreren Bedingungen der angegebenen Operanden unter Verwendung der logischen Operatoren AND, OR und NOT in C zu demonstrieren.
/* program to check the various condition using the logical NOT operator in c. */ #include #include int main () { // declare and initialize variables int a = 20, b = 15; int n1 = 15, n2 = 17; // use logical 'AND' and logical 'NOT' operator if (a > b && a != 0) { printf (' The AND (&&) operator said: Both conditions are true. '); } // use logical 'OR' and logical 'NOT' operator if (n1 > n2 || n2 != 15) if ( ! (a > b && a != 0 )) { printf (' The NOT (!) operator: Here both conditions are true. '); } else { printf (' The NOT (!) operator: Here, both conditions are true. ' ' But, the status of the condition is reversed as false. '); } return 0; }
Ausgabe:
The AND (&&) operator is said: Both conditions are true. The OR (||) operator is said: Only one condition is true. The NOT (!) operator: Here, both conditions are true. But, the status of the condition is reversed as false.
3));>