Description

If the age of the person is greater than 17 (age>17) or greater than equal to 18 (age>=18) then the person is eligible for voting.

In this tutorial we solve this problem using switch statement in c.

Method 1 using switch statement

#include <stdio.h>

int main() {
    int age;
    printf("Enter the age of candidate : ");
    scanf("%d", &age);
    switch (age){
        case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:
            printf("You are not Elegible for Voting");
            break;
        case 18: case 19:case 20:case 21:case 22:case 23:case 24:case 25:case 26:case 27:case 28:case 29:case 30:case 31:case 32:case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 40:case 41:case 42:case 43:case 44:case 45:case 46:case 47:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:case 58:case 59:case 60:case 61:case 62:case 63:case 64:case 65:case 66:case 67:case 68:case 69:case 70:case 71:case 72:case 73:case 74:case 75:case 76:case 77:case 78:case 79:case 80:case 81:case 82:case 83:case 84:case 85:case 86:case 87:case 88:case 89:case 90:
            printf("You are Elegible For Voting");
        
    }

    return 0;
}

/*

Enter the age of candidate : 23
You are Elegible For Voting

*/

Method 2 Using switch Statement

// Online C compiler to run C program online
#include <stdio.h>

int main() {
    
    int age, flag = 0;
    printf("Enter the Candidate age : ");
    scanf("%d", &age);
    if(age >= 18){
        flag = 1;
    }
    
    switch(flag){
        case 1:
            printf("You are eligible for voting");
            break;
        case 0:
            printf("You are not eligible for voting");
            break;
    }
    return 0;
}

/*

Enter the Candidate age : 17
You are not eligible for voting

*/

Please Comment...

Comments

Login is mandatory to comment Please login

Recommended Posts

C program to convert decimal to binary without Array

We can convert any decimal number into binary number by c program without using array.

A C program for checking whether a given line is a comment

Write a program in c to check whether a given line is comment or not.

Linear search in c | Algorithm of Linear search | c programming

It is the easiest search algorithm because it starts at the beginning and works through each element in a list until the desired element is located.

calculate the GCD | Euclids Algorithm | c and cpp programming language

The G.C.D. ( Greatest Common Divisor ) or H.C.F. ( Highest Common Factor ) of two numbers is the largest positive integer that perfectly divides the two given numbers.

Implement queue using linked list C program

In computing, queues are linear data structures that follow the First In, First Out (FIFO) principle. They are used to perform enqueuing and dequeuing operations.

Fascinating number or not in c and cpp

Check given number is fascinating number or not in c programming language.