Definition:
The if-else statement is a decision-making statement in C programming. It is used to execute one block of code when a condition is true and another block of code when the condition is false.
Explanation: This program accepts two numbers from the user and displays the greater number using the if-else statement.
#include <stdio.h> #include <conio.h> main() { int No1, No2; clrscr(); printf("Enter the First No : "); scanf("%d",&No1); printf("Enter the Second No : "); scanf("%d",&No2); if(No1 > No2) { printf("\nNo 1 is greater"); } else { printf("\nNo 2 is greater"); } getch(); }
Output:
if-else statement.if-else statement.> operator.
#include <stdio.h> #include <conio.h> main() { int a,b; clrscr(); printf("Enter First Number : "); scanf("%d",&a); printf("Enter Second Number : "); scanf("%d",&b); if(a > b) { printf("\nFirst Number is Greater"); } else { printf("\nFirst Number is Not Greater"); } getch(); }
> operator. If the first number is greater than the second number, it displays "First Number is Greater"; otherwise, it displays "First Number is Not Greater".