C Programs - Conditional


In C language, statements are executed sequentially.

But sometimes we want to execute some part of our code conditionally or we need to make decision based on some condition.

In C language following types of conditional statements can be used:

  1. if statement
  2. if-else statement
  3. if-else ladder
  4. Nested if-else statement
  5. switch statement
  6. Conditional / Ternary operator

In this section, we will try programs based on conditional statements mentioned above.

List of programs: if-else

  1. C program to check if number is even or odd
  2. C Program to find maximum between two numbers
  3. C Program to find maximum between three numbers
  4. C Program to check if number is positive, negative or zero
  5. C program to check if a year is leap year or not
  6. C program to check if a character is alphabet or not
  7. C program to check if a given alphabet is vowel or consonant
  8. C program to check if a given character is an alphabet, digit, or special character
  9. C program to check if a character is uppercase or lowercase alphabet
  10. C program to input angles of a triangle and check whether triangle is valid or not
  11. C program to input all sides of a triangle and check if triangle is valid or not
  12. C program to check if the triangle is equilateral, isosceles or scalene triangle
  13. C program to find all roots of a quadratic equation
  14. C program to calculate profit or loss

List of programs: conditional / ternary

  1. C program to find maximum between two numbers using ternary operator
  2. C program to find maximum between three numbers using ternary operator
  3. C program to check if a number is even or odd using ternary operator
  4. C program to check if a character is an alphabet or not using ternary operator