Software & Finance





Turbo C - Simple IF ELSE Statement





Here is an example for simple if else statement.

 

if statement evaluates the condition inside the paranthesis and if it is true, then it executes one line followed by if statement or the sequence of steps bound of { }.

 

if statement can be combined with else part. Else part will be executed when the if condition is false.

 


Source Code


#include <stdio.h>

 

 

void main()

{

   int x;

 

   printf("Enter a Number: ");

   scanf("%d", &x);

 

   if(x < 0)

      printf("%d is a negative number\n", x);

   else

      printf("%d is a positive number\n", x);

}

 

Output


Enter a Number: -100

-100 is a negative number

 

Enter a Number: 55

55 is a positive number