> For the complete documentation index, see [llms.txt](https://mun.gitbook.io/c/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mun.gitbook.io/c/solution/3-conditional-statements/3.1-conditional-statement.md).

# 3.1 Conditional Statement

## কন্ডিশনাল স্টেটমেন্ট (৪)

1. শূন্য, ধনাত্মক, ঋণাত্মক - সংখ্যার চিহ্ন নির্ণয়
   1. \[1.1] একটি পূর্ণসংখ্যা শূন্য কিনা নির্ণয় কর। *(Similar)*
   2. \[1.2] একটি পূর্ণসংখ্যা ধনাত্মক না ঋণাত্মক নির্ণয় কর। *(Similar)*
   3. \[1] একটি পূর্ণসংখ্যা শূন্য না ধনাত্মক না ঋণাত্মক নির্ণয় কর।
2. \[2] **বয়স** অনুযায়ী একজন ব্যাক্তি ভোটার কিনা নির্ণয় কর।
3. \[3] **বয়স** অনুযায়ী চাকরির আবেদন করার যোগ্য কিনা নির্ণয় কর। (নির্ধারিত বয়সসীমা ১৮ থেকে ৩৫)
4. \[4] **দুইটি জটিল সংখ্যা** সমান কিনা নির্ণয় কর।

## সমাধান

### \[1.1] একটি পূর্ণসংখ্যা শূন্য কিনা নির্ণয় কর।

{% tabs %}
{% tab title="Partial Solution" %}
{% code lineNumbers="true" %}

```c
#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;
}
```

{% endcode %}
{% endtab %}

{% tab title="only if solution" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}

{% tab title="if else solution" %}
{% code lineNumbers="true" %}

```c
#include<stdio.h>
int main(){
    int a = 0; // Output => Zero
    //int a = 1; // Output => Not Zero
    
    if( a == 0 ){
        printf("Zero\n");
    }
    else{ // Else block will execute when (a == 0) is false
        printf("Not Zero\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}

{% tab title="advanced solution" %}
{% code lineNumbers="true" %}

```c
#include<stdio.h>
int main(){
    int a = 0; // Output => Zero
    //int a = 1; // Output => Not Zero
    
    if( a ){ // if evaluate 0 as FALSE and non-zero value as TRUE
    // This block will execute when the value of a is non-zero
        printf("Not Zero\n");
    }
    else{
    // This block will execute when the value of a is 0
        printf("Zero\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}

{% tab title="more advanced" %}
{% code lineNumbers="true" %}

```c
#include<stdio.h>
int main(){
    int a = 0; // Output => Zero
    //int a = 1; // Output => Not Zero
    
    // Logical NOT Operator
    if( !a ){ // when a=0, it means a is FALSE, !a means TRUE
    // This block will execute when the value of a is 0
        printf("Zero\n");
    }
    else{
    // This block will execute when the value of a is non-zero
        printf("Not Zero\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### \[1.2] একটি পূর্ণসংখ্যা ধনাত্মক না ঋণাত্মক নির্ণয় কর।

{% tabs %}
{% tab title="only if solution" %}
{% code lineNumbers="true" %}

```c
#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;
}
```

{% endcode %}
{% endtab %}

{% tab title="if else solution" %}
{% code lineNumbers="true" %}

```c
#include<stdio.h>
int main(){
    int a = 5; // Output => Positive
    //int a = -5; // Output => Negative
    //int a = 0; // Output => Negative
    
    if( a > 0 ){ // Testing Grater Then Operator [>]
        printf("Positive\n");
    }
    else{ // Else block will execute when (a > 0) is false
        printf("Negative\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}

{% tab title="next solution" %}
{% code lineNumbers="true" %}

```c
#include<stdio.h>
int main(){
    int a = 5; // Output => Positive
    //int a = -5; // Output => Negative
    //int a = 0; // Output => Positive
    
    if( a >= 0 ){ // Testing Grater Then or Equal Operator [>=]
        printf("Positive\n");
        // Zero is neither Position nor Negative
        // So This Solution is not perfect
    }
    else{ // Else block will execute when (a > 0) is false
        printf("Negative\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### \[1] একটি পূর্ণসংখ্যা শূন্য না ধনাত্মক না ঋণাত্মক নির্ণয় কর।

{% tabs %}
{% tab title="only if solution" %}
{% code lineNumbers="true" %}

```c
#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;
}
```

{% endcode %}
{% endtab %}

{% tab title="if else if solution" %}
{% code lineNumbers="true" %}

```c
#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");
    }
    else if( num < 0 ){ // Testing Less Then Operator [<]
        printf("Negative\n");
    }
    else if( num == 0 ){ // Testing Equlity Operator [==]
        printf("Zero\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}

{% tab title="if else if ladder solution" %}
{% code lineNumbers="true" %}

```c
#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");
    }
    else if( num < 0 ){ // Testing Less Then Operator [<]
        printf("Negative\n");
    }
    else{
    // This else block will execute when both previous conditions are false
        printf("Zero\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}

{% tab title="Nested Connditional Statement" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

| Sample Input | Sample Output |
| ------------ | ------------- |
| `5`          | `Positive`    |
| `-3`         | `Negative`    |
| `0`          | `Zero`        |

### \[2] বয়স অনুযায়ী একজন ব্যাক্তি ভোটার কিনা নির্ণয় কর।

#### Test Voting Eligibility 1 (only if solution)

{% tabs %}
{% tab title="Partial Solution" %}
{% code lineNumbers="true" %}

```c
#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;
}
```

{% endcode %}
{% endtab %}

{% tab title="only if solution" %}
{% code lineNumbers="true" %}

```c
#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");
    }
    if(age > 18){
        printf("Eligible to Vote\n");
    }
    if(age < 18){
        printf("Not Eligible to Vote\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}

{% tab title="Logical Operator (OR) Solution" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}

{% tab title="better solution" %}
{% code lineNumbers="true" %}

```c
#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");
    }
    if(age < 18){
        printf("Not Eligible to Vote\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Test Voting Eligibility 2 (if else solution)

{% tabs %}
{% tab title="if else if solution" %}
{% code lineNumbers="true" %}

```c
#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;
}
```

{% endcode %}
{% endtab %}

{% tab title="if else solution" %}
{% code lineNumbers="true" %}

```c
#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{
        printf("Not Eligible to Vote\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}

{% tab title="advanced solution" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

#### Test Voting Eligibility 3 (alternative solution)

{% tabs %}
{% tab title="alternative solution 1" %}
{% code lineNumbers="true" %}

```c
#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;
}
```

{% endcode %}
{% endtab %}

{% tab title="alternative solution 2" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

### \[3] বয়স অনুযায়ী চাকরির আবেদন করার যোগ্য কিনা নির্ণয় কর। (নির্ধারিত বয়সসীমা ১৮ থেকে ৩৫)

{% tabs %}
{% tab title="Nested Condition" %}
{% code lineNumbers="true" %}

```c
#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;
}
```

{% endcode %}
{% endtab %}

{% tab title="Logical AND" %}
{% code lineNumbers="true" %}

```c
#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 && age <= 35){ // Testing Logical AND Operator [&&]
    // Print "Eligible to apply" if the age is between 18 and 35 inclusive
        printf("Eligible to apply\n");
    }
    else{
    // Print "Not Eligible to apply" if the age is outside the range
        printf("Not eligible to apply\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}

{% tab title="advanced solution" %}
{% code lineNumbers="true" %}

```c
#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 Less Then or Equal Operator [<=]
        printf("Not eligible to apply\n");
    }
    else if( age >= 35 ){ // Testing Grater Then or Equal Operator [>=]
        printf("Not eligible to apply\n");
    }
    else{
        printf("Eligible to apply\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}

{% tab title="Logical OR" %}
{% code lineNumbers="true" %}

```c
#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 || age >= 35){ // Testing Logical OR Operator [||]
        printf("Not eligible to apply\n");
    }
    else{
        printf("Eligible to apply\n");
    }
    
    return 0;
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

| Sample Input | Sample Output         |
| ------------ | --------------------- |
| 20           | Eligible to apply     |
| 15           | Not Eligible to apply |
| 38           | Not Eligible to apply |

### \[4] দুইটি জটিল সংখ্যা সমান কিনা নির্ণয় কর।

{% tabs %}
{% tab title="Nested Conditional Statement" %}
{% code lineNumbers="true" %}

```c
#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;
}
```

{% endcode %}
{% endtab %}

{% tab title="Logical Operator (AND) Solution" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

| Sample Input | Sample Output                       |
| ------------ | ----------------------------------- |
| `3 4` `3 4`  | `The complex numbers are equal`     |
| `5 6` `5 7`  | `The complex numbers are not equal` |
