3.1 Conditional Statement

āĻ•āĻ¨ā§āĻĄāĻŋāĻļāύāĻžāϞ āĻ¸ā§āĻŸā§‡āϟāĻŽā§‡āĻ¨ā§āϟ (ā§Ē)

  1. āĻļā§‚āĻ¨ā§āϝ, āϧāύāĻžāĻ¤ā§āĻŽāĻ•, āĻ‹āĻŖāĻžāĻ¤ā§āĻŽāĻ• - āϏāĻ‚āĻ–ā§āϝāĻžāϰ āϚāĻŋāĻšā§āύ āύāĻŋāĻ°ā§āϪ⧟

    1. [1.1] āĻāĻ•āϟāĻŋ āĻĒā§‚āĻ°ā§āĻŖāϏāĻ‚āĻ–ā§āϝāĻž āĻļā§‚āĻ¨ā§āϝ āĻ•āĻŋāύāĻž āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤ (Similar)

    2. [1.2] āĻāĻ•āϟāĻŋ āĻĒā§‚āĻ°ā§āĻŖāϏāĻ‚āĻ–ā§āϝāĻž āϧāύāĻžāĻ¤ā§āĻŽāĻ• āύāĻž āĻ‹āĻŖāĻžāĻ¤ā§āĻŽāĻ• āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤ (Similar)

    3. [1] āĻāĻ•āϟāĻŋ āĻĒā§‚āĻ°ā§āĻŖāϏāĻ‚āĻ–ā§āϝāĻž āĻļā§‚āĻ¨ā§āϝ āύāĻž āϧāύāĻžāĻ¤ā§āĻŽāĻ• āύāĻž āĻ‹āĻŖāĻžāĻ¤ā§āĻŽāĻ• āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤

  2. [2] āĻŦ⧟āϏ āĻ…āύ⧁āϝāĻžā§Ÿā§€ āĻāĻ•āϜāύ āĻŦā§āϝāĻžāĻ•ā§āϤāĻŋ āĻ­ā§‹āϟāĻžāϰ āĻ•āĻŋāύāĻž āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤

  3. [3] āĻŦ⧟āϏ āĻ…āύ⧁āϝāĻžā§Ÿā§€ āϚāĻžāĻ•āϰāĻŋāϰ āφāĻŦ⧇āĻĻāύ āĻ•āϰāĻžāϰ āϝ⧋āĻ—ā§āϝ āĻ•āĻŋāύāĻž āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤ (āύāĻŋāĻ°ā§āϧāĻžāϰāĻŋāϤ āĻŦ⧟āϏāϏ⧀āĻŽāĻž ā§§ā§Ž āĻĨ⧇āϕ⧇ ā§Šā§Ģ)

  4. [4] āĻĻ⧁āχāϟāĻŋ āϜāϟāĻŋāϞ āϏāĻ‚āĻ–ā§āϝāĻž āϏāĻŽāĻžāύ āĻ•āĻŋāύāĻž āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤

āϏāĻŽāĻžāϧāĻžāύ

[1.1] āĻāĻ•āϟāĻŋ āĻĒā§‚āĻ°ā§āĻŖāϏāĻ‚āĻ–ā§āϝāĻž āĻļā§‚āĻ¨ā§āϝ āĻ•āĻŋāύāĻž āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤

#include<stdio.h>
int main(){
    int a = 0; // Output => Zero
    //int a = 1; // No Output
    
    if( a == 0 ){ // Testing Equlity Operator [==]
        printf("Zero\n");
    }
    
    return 0;
}

[1.2] āĻāĻ•āϟāĻŋ āĻĒā§‚āĻ°ā§āĻŖāϏāĻ‚āĻ–ā§āϝāĻž āϧāύāĻžāĻ¤ā§āĻŽāĻ• āύāĻž āĻ‹āĻŖāĻžāĻ¤ā§āĻŽāĻ• āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤

#include<stdio.h>
int main(){
    int a = 5; // Output => Positive
    //int a = -5; // Output => Negative
    //int a = 0; // No Output
    
    if( a > 0 ){ // Testing Grater Then Operator [>]
        printf("Positive\n");
    }
    if( a < 0 ){ // Testing Less Then Operator [<]
        printf("Negative\n");
    }
    
    return 0;
}

[1] āĻāĻ•āϟāĻŋ āĻĒā§‚āĻ°ā§āĻŖāϏāĻ‚āĻ–ā§āϝāĻž āĻļā§‚āĻ¨ā§āϝ āύāĻž āϧāύāĻžāĻ¤ā§āĻŽāĻ• āύāĻž āĻ‹āĻŖāĻžāĻ¤ā§āĻŽāĻ• āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤

#include<stdio.h>
int main(){
    int num = 5; // Output => Positive
    //int num = -5; // Output => Negative
    //int num = 0; // Output => Zero
    
    if( num > 0 ){ // Testing Grater Then Operator [>]
        printf("Positive\n");
    }
    if( num < 0 ){ // Testing Less Then Operator [<]
        printf("Negative\n");
    }
    if( num == 0 ){ // Testing Equlity Operator [==]
        printf("Zero\n");
    }
    
    return 0;
}
Sample Input
Sample Output

5

Positive

-3

Negative

0

Zero

[2] āĻŦ⧟āϏ āĻ…āύ⧁āϝāĻžā§Ÿā§€ āĻāĻ•āϜāύ āĻŦā§āϝāĻžāĻ•ā§āϤāĻŋ āĻ­ā§‹āϟāĻžāϰ āĻ•āĻŋāύāĻž āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤

Test Voting Eligibility 1 (only if solution)

#include<stdio.h>
int main(){
    int age = 20; // Output => Voter
    //int age = 15; // Output => Not Voter
    //int age = 18; // No Output
 
    if(age > 18){
        printf("Eligible to Vote\n");
    }
    if(age < 18){
        printf("Not Eligible to Vote\n");
    }
    
    return 0;
}

Test Voting Eligibility 2 (if else solution)

#include<stdio.h>
int main(){
    int age = 20; // Output => Voter
    //int age = 15; // Output => Not Voter
    //int age = 18; // Output => Voter
 
    if(age >= 18){
        printf("Eligible to Vote\n");
    }
    else if(age < 18){
        printf("Not Eligible to Vote\n");
    }
    
    return 0;
}

Test Voting Eligibility 3 (alternative solution)

#include<stdio.h>
int main(){
    int age = 20; // Output => Voter
    //int age = 15; // Output => Not Voter
    //int age = 18; // Output => Voter
 
    if(age < 18){
        printf("Not Eligible to Vote\n");
    }
    else{
        printf("Eligible to Vote\n");
    }
    
    return 0;
}

[3] āĻŦ⧟āϏ āĻ…āύ⧁āϝāĻžā§Ÿā§€ āϚāĻžāĻ•āϰāĻŋāϰ āφāĻŦ⧇āĻĻāύ āĻ•āϰāĻžāϰ āϝ⧋āĻ—ā§āϝ āĻ•āĻŋāύāĻž āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤ (āύāĻŋāĻ°ā§āϧāĻžāϰāĻŋāϤ āĻŦ⧟āϏāϏ⧀āĻŽāĻž ā§§ā§Ž āĻĨ⧇āϕ⧇ ā§Šā§Ģ)

#include<stdio.h>
int main(){
    int age = 20; // Output => Eligible to apply
    //int age = 15; // Output => Not Eligible to apply
    //int age = 38; // Output => Not Eligible to apply
 
    if(age >= 18){ // Testing Grater Then or Equal Operator [>=]
        if( age <= 35 ){ // Testing Less Then or Equal Operator [<=]
            printf("Eligible to apply\n");
        }
        else{
            printf("Not eligible to apply\n");
        }
    }
    else{
        printf("Not eligible to apply\n");
    }
    
    return 0;
}
Sample Input
Sample Output

20

Eligible to apply

15

Not Eligible to apply

38

Not Eligible to apply

[4] āĻĻ⧁āχāϟāĻŋ āϜāϟāĻŋāϞ āϏāĻ‚āĻ–ā§āϝāĻž āϏāĻŽāĻžāύ āĻ•āĻŋāύāĻž āύāĻŋāĻ°ā§āϪ⧟ āĻ•āϰāĨ¤

#include<stdio.h>
int main(){
    int a1 = 0, b1 = 1, a2 = 0, b2 = 1; // Output => Equal
    //int a1 = 1, b1 = 1, a2 = 0, b2 = 0; // Output => Not Equal
    
    if( a1 == a2 ){
        if( b1 == b2 ){
            printf("Equal\n");
        }
        else{
            printf("Not Equal\n");
        }
    }
    else{
        printf("Not Equal\n");
    }
    
    return 0;
}
Sample Input
Sample Output

3 4 3 4

The complex numbers are equal

5 6 5 7

The complex numbers are not equal

Last updated