Learn how to use logical operators (&&, ||) to compare three numbers and find the largest.
To write a C/C++ program that takes three numbers as input from the user and displays the largest number using logical operators (&& and ||).
In this practical, you will learn how to find the largest of three numbers using logical operators. Logical operators are used to combine multiple conditions:
The logic for finding the largest number:
num1 > num2 && num1 > num3, then num1 is the largest.num2 > num1 && num2 > num3, then num2 is the largest.num3 is the largest.&& operator checks if both conditions are true. For example, num1 > num2 && num1 > num3 means "num1 is greater than num2 AND num1 is greater than num3".
&&) operator.Run the program:
Sample Input & Output:
| Operator | Name | Meaning | Example |
|---|---|---|---|
&& |
AND | Both conditions must be true | num1 > num2 && num1 > num3 |
|| |
OR | At least one condition must be true | num1 > num2 || num1 > num3 |
&& operator is used to check if one number is greater than both other numbers.if-else structure correctly identifies the largest number.
You have successfully written a C program that finds the largest of three numbers using logical operators (&&). You have learned how to combine multiple conditions in an if statement to compare three values.
&& operator checks if both conditions are true. If both are true, the entire condition becomes true. If either condition is false, the entire condition is false.
&& operators.
ایک C/C++ پروگرام لکھنا جو صارف سے تین اعداد ان پٹ کے طور پر لے اور منطقی آپریٹرز (&& اور ||) کا استعمال کرتے ہوئے سب سے بڑا عدد ظاہر کرے۔
اس عملی میں، آپ منطقی آپریٹرز کا استعمال کرتے ہوئے تین اعداد میں سے سب سے بڑا عدد تلاش کرنا سیکھیں گے۔ منطقی آپریٹرز کو متعدد شرائط کو یکجا کرنے کے لیے استعمال کیا جاتا ہے:
سب سے بڑا عدد تلاش کرنے کی منطق:
num1 > num2 && num1 > num3، تو num1 سب سے بڑا ہے۔num2 > num1 && num2 > num3، تو num2 سب سے بڑا ہے۔num3 سب سے بڑا ہے۔&& آپریٹر چیک کرتا ہے کہ کیا دونوں شرائط درست ہیں۔ مثال کے طور پر، num1 > num2 && num1 > num3 کا مطلب ہے "num1 num2 سے بڑا ہے اور num1 num3 سے بڑا ہے"۔
پروگرام چلائیں:
نمونہ ان پٹ اور آؤٹ پٹ:
| آپریٹر | نام | معنی | مثال |
|---|---|---|---|
&& |
AND | دونوں شرائط درست ہونی چاہئیں | num1 > num2 && num1 > num3 |
|| |
OR | کم از کم ایک شرط درست ہونی چاہیے | num1 > num2 || num1 > num3 |
&& آپریٹر کا استعمال یہ چیک کرنے کے لیے کیا جاتا ہے کہ آیا ایک عدد دوسرے دونوں اعداد سے بڑا ہے۔if-else ڈھانچہ سب سے بڑے عدد کی درست شناخت کرتا ہے۔
آپ نے کامیابی سے ایک C پروگرام لکھا ہے جو منطقی آپریٹرز (&&) کا استعمال کرتے ہوئے تین اعداد میں سے سب سے بڑا عدد تلاش کرتا ہے۔ آپ نے سیکھ لیا ہے کہ تین قدروں کا موازنہ کرنے کے لیے if بیان میں متعدد شرائط کو کیسے یکجا کیا جاتا ہے۔
&& آپریٹر چیک کرتا ہے کہ آیا دونوں شرائط درست ہیں۔ اگر دونوں درست ہیں تو پوری شرط درست ہو جاتی ہے۔ اگر کوئی بھی شرط غلط ہے تو پوری شرط غلط ہے۔
&& آپریٹرز کے ساتھ مزید شرائط شامل کرکے اس پروگرام کو 4، 5 یا اس سے زیادہ اعداد میں سب سے بڑا عدد تلاش کرنے کے لیے بڑھا سکتے ہیں۔