slide06-Selection Structures - ICS 103 Computer Programming in C Handout-6 Topic Control Structures(Selection Structures Objective To Know about re

# slide06-Selection Structures - ICS 103 Computer Programming...

This preview shows page 1 - 4 out of 11 pages.

ICS 103: Computer Programming in C Handout-6 Topic: Control Structures (Selection Structures) Objective: To Know about relational and logical operators of C language and their use. To know about order of execution of relational and logical operators with others operators. To Know syntax and use of if , if else , Nested if , if … else if … else , switch Selection Statements. Relational and Logical operators : The most commonly used relational operators are > for greater than >= for greater than or equal to < for less than <= for less than or equal to == for equal to != for not equal to The most commonly used logical operators are && for binary AND | | for binary OR ! for unary NOT These operators are used in the expression  of  if statement. The expression having these operators is called Logical expression. Operator Precedence: Operator Precedence ! (not) , +, - , & (address of) ; Note  Above  are  Unary  Operators  which  have  a single  operand.      Ist (i.e   highest ) * , /, % IInd Page 1 of 11
+ , - IIIrd < , <= , >=, > IVth == (equality operator), != (not equal) . Vth && (logical and operator ) . VIth || (logical OR operator ) . VIIth = (assignment operator) . VIIIth (i.e Lowest ) Examples: To check if the value of the integer variable x is more than 5 and less than 10 or equal to 15 , we write x > 5 && x < 10 | | x == 15 To check if the value of the float variable a is not equal to 1.5 or less than or equal to 2.5 but more than or equal to 1.5 , we write a != 1.5 | | a <= 2.5 && a >= 1.5 Output Example #include<stdio.h> int main(void) { int u=-2; printf("%d\n",!0*3+-2); printf("%d\n",1==5>=3); printf("%d\n",2-5>-4||!5&&0); printf("%d\n",-13%5); printf("%d",3<11+u||-5*2!=5); return 0; } Selection Structures : Page 2 of 11
One-Way Selection Using the if-statement: Syntax : if (expression) Statement; If the expression  is true , then  the   statement  is executed ; otherwise  the   statement  is ignored . For example,  let  marks be an integer variable. To check the value of marks to see if it is more  than   75 and print PASS if it is more than 75 we would write if (marks > 75) printf (“PASS\n”) ; If marks is less  than  or  equal  to  75

#### You've reached the end of your free preview.

Want to read all 11 pages?

• Spring '10
• zaman
• Equals sign, relational operator, printf

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern