In the simplest situation, the statement to be performed conditionally is placed after a test, using the construction
if (condition) statementand the statement is only performed if the condition is true. The condition is any integer expression, with zero interpreted as false, all other values as true. An example is
if (IntVal>4) printf("Greater\n");In other situations we may wish to have one statement executed if a condition is true and another if it is false. This uses the extended form
if (condition) statement else statementand an example is
if (IntVal>4) printf("Greater"); else printf("Not greater");
#include <stdio.h> /*Reads 2 chars and writes the mean of their integer code*/ void main() { int Val1, Val2, Result; Val1 = getchar(); Val2 = getchar(); Result = Val1 + Val2; Result = Result / 2; printf("%d", Result); printf(" which is "); if (Result>10) printf("not "); printf("less than 11"); }Simple text version to compile