if else

If we want to execute the particular statement on the basis of certain condition, called if else statement.

Syntax

    if(condition)
{

//body to execute

}

else

{

//body to execute

}

Example

C program to input a no and check negative no. or positive no./find nature.

void  main()
{
int num;
printf("Enter a No.\n");
scanf("%d\n",&num);
if(num>0)
{
printf("Number is Positive");
}
else
{
printf("Number is Negative");
}

getch();
}

Input :       -5
Output:     Number is  Negative






Related Posts:

  • Simple if Statement : C Programming                  C Programming Simple if Statement The statement which executes on the basis of certain condition is called simple if statement… Read More
  • Control Statement : C Programming C Programming Control Statement The statement which control the flow of control is called control statement.    C Provides following types of control statement- 1. Selective Statement or Conditional Statement. … Read More
  • If-else-If ladder : C Programming                C Programming If else-if ladder The if else ladder statement in C programming language is used to test set of conditions in sequence. A… Read More
  • Constants in C : C Programming C Programming Constants in C A constant variable is such type of variable that's value can't be changed during execution of the program. Constants in C ConstantExample Decimal Constant10, 20, 450 etc. Real or Floating-p… Read More
  • If else : C Programming C Programming if else If we want to execute the particular statement on the basis of certain condition, called if else statement. Syntax     if(condition) { //body to execute } else { //body to execu… Read More