C – If Else Block

Else Block: It executes when the given condition of if block fails. Else block is optional for if block. Else block cannot be defined without IF block.

Program to check the input number is Positive or Not:

Positive Number: The number greater than 0 is called positive number.

#include<stdio.h>
int main()
{
            int num;
            printf(“Enter number : “);
            scanf(“%d”, &num);
            if(num>0)
                        printf(“Positive number \n”);
            else
                        printf(“Not Positive number \n”);
            return 0;
}

Program to check the Person eligible for Vote or Not:

#include<stdio.h>
int main()
{
            int age;
            printf(“Enter age : “);
            scanf(“%d”, &age);
            if(age>=18)
                        printf(“You are eligible for Vote \n”);
            else
                        printf(“You are not eligible for Vote \n”);
            return 0;
}

Program to find the biggest of 2 numbers:

#include<stdio.h>
int main()
{
            int a, b;
            printf(“Enter a value : “);
            scanf(“%d”, &a);
            printf(“Enter b value : “);
            scanf(“%d”, &b);
            if(a>b)
                        printf(“a is big \n”);
            else
                        printf(“b is big \n”);
            return 0;
}

Program to check the number is Even or not:

Even Number: The number which is divisible by 2 is called Even number.

#include<stdio.h>
int main()
{
            int n;   
            printf(“Enter number : “);
            scanf(“%d”, &n);
            if(n%2==0)
                        printf(“%d is Even \n”, n);
            else
                        printf(“%d is not Even \n”, n);
            return 0;
}

Program to check the number divisible by both 3 and 5 or not:

#include<stdio.h>
int main()
{
            int n;   
            printf(“Enter number : “);
            scanf(“%d”, &n);
            if(n%3==0 && n%5==0)
                        printf(“%d divisible by both 3 and 5 \n”, n);
            else
                        printf(“%d is not divisible by both 3 and 5 \n”, n);
            return 0;
}

Program to check the character is Vowel or not:

int main()
{
            char ch;           
            printf(“Enter character : “);
            scanf(“%c”, &ch);
            if(ch==’a’ || ch==’e’ || ch==’i’ || ch==’o’ || ch==’u’)
                        printf(“Given character is Vowel \n”);
            else
                        printf(“Given character is not Vowel \n”);
            return 0;
}
Scroll to Top