1 / 12

Mastering Conditionals in C Programming: Relational and Logical Operators Explained

Dive into the world of conditionals in C programming with this comprehensive guide. Learn about relational operators for comparisons, logical operators for combining conditions, and the syntax for conditional branching using `if`, `if-else`, and nested `if` statements. Explore practical examples, such as salary increments based on age and class distinctions based on marks. By the end of this tutorial, you'll have a solid understanding of how to control the flow of your programs with conditionals. Perfect for beginners and anyone looking to enhance their C programming skills!

aiden
Télécharger la présentation

Mastering Conditionals in C Programming: Relational and Logical Operators Explained

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