If Else Statement In C Language

1) If Statement

The single if else statement in C language is used to execute the code if a condition is true. It is also called one-way selection statement.

Syntax:-

if(expression)
{
//code to be executed
}

For Example,

  1. Write a program to find the given number is positive number

#include<stdio.h>

#include<conio.h>

int main()
{
int number;
printf(“Enter any numbern”);
scanf(“%d”,&number);
if( number > 0 )
{
printf(“You Have Entered Positive Integern”);
}
getch();
return 0;
}


2) If Else Statement

The if-else statement in C language is used to execute the code if condition is true or false. It is also called two-way selection statement.

Syntax:-

if(expression)
{
//Statements
}
else
{
//Statements
}

For Example,

  1. Write a program to find the given number is positive number or negative number

#include<stdio.h>

#include<conio.h>

int main()
{
int number;
printf(“Enter any numbern”);
scanf(“%d”,&number);
if( number > 0 )
{
printf(“You Have Entered Positive numbern”);
}
else
{
printf(“You Have Entered negative number n”);
}

getch();
return 0;
}


Do the Following programs

  1. Write a program to find the given person the eligible for voting or not
  2. Write a program to find the given number is even or odd number
  3. Write a program to find the given student is fail or pass in the given subject
  4. Write a program to find the given year is leap year
Scroll to Top