All programs related to if-else are available here in C language.

All programs related to if-else are available here in C language.

If-else:

The statement is used to test a condition and take one of the two possible actions. If the condition is true then a single statement or a block of statements is executed (one part of the program), otherwise another single statement or a block of statements is executed (other part of the program). Recall that in C, any nonzero value is regarded as true while zero is regarded as false.

Syntax 1:

    if (condition)
      {
         statement;
         .........
      }

There can be a single statement or a block of statements after the if part.

if else single statement

Flow chart of if control statement


Here if the condition is true (nonzero) then statement 1 is executed, and if it is false(zero), then the next statement which is immediately after the if control statement is executed.

Syntax 2:

if(condition)
  {
      statement;
      .........
  }
  else
  {
      statement;
      .........
  }
if else conditions

Flow chart of if-else control statement


Here if the condition is true then statement is executed and if it is false then statement2 is executed. After this the control transfers to the next statement which is immediately after the if-else control statement.

Some programs related to if-else for students are given below:

  1. Area of Rectangle code
  2. Program to check a number is divisible by 5 or not
  3. Which number is divisible by 5 or 3 but not 15
  4. Largest number among to three number
  5. Check year is leap year or not in c
  6. C Program to check whether the number is Odd or Even

*

Post a Comment (0)
Previous Post Next Post