1 / 12

C Programming

C Programming. (Conditionals) Date : 30 th Jan 2012. Relational Operators . Logical Operators. Conditional Branching : if ( Syntax ). if ( expression ) /* if expression is true */ { statement(s); }. Conditional Branching : if (example).

aiden
Download Presentation

C Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C Programming (Conditionals) Date : 30th Jan 2012

  2. Relational Operators

  3. Logical Operators

  4. Conditional Branching : if (Syntax) if (expression) /* if expression is true */ { statement(s); }

  5. Conditional Branching : if (example) if (age < 25) /* if expression is true */ { salary = salary * 1.1; printf(“\n\nThe salary is incremented by 10%.”); }

  6. “if-else” Syntax if (expression) /* if expression is true */ { statement(s); } else /* if expression is false */ { statement(s); }

  7. If-else (example) if (age < 25) /* if expression is true */ { salary = salary * 1.1; printf(“\n\nThe salary is incremented by 10%.”); } else /* if expression is false */ { salary = salary * 1.2; printf(“\n\nThe salary is incremented by 20%.”); }

  8. “if-else if” Syntax if (expression 1) /* if expression 1 is true */ { statement(s); } else if (expression 2) /* if expression 2 is true */ { statement(s); } else /* if both expressions are false */ { statement(s); }

  9. “if-else if” (example) if (marks > 60) /* if expression is true */ { printf(“First Class…!”); } else if (marks > 50)/* if expression is true */ { printf(“Second Class…!”); } else if (marks > 40) /* if expression is true */ { printf(“Pass Class…!”); } else /* otherwise */ { printf(“Failed…!”) }

  10. Nested “if” (Syntax) if(expression 1) { if(expression 2) { statement(s); // if both expressions are true } }

  11. Nested “if” (Example) if(age > 25) { if(age < 30) { printf(“Age is between 25 and 30…!”); } else { printf(“Age is more than or equal to 30…!”); } } else { printf(Age is less than or equal to 25…!); }

  12. Logical Operators (example) if(age > 25 && experience > 5) { printf(“Qualified for promotion…!”); } ------------------------------------------------------------- if(age > 40 || experience > 10) { printf(“Qualified for promotion…!”); } ------------------------------------------------------------- if(! (age >= 18)) { printf(“You can’t get a driving license…!”); }

More Related