Saturday, 24 February 2024

Tutorial 09

    

    Program Control Structures - Decision Making & Branching


Question 01

Swap two values stored in two different variables.

C Code

        #include <stdio.h>
        int main() 
        {
            int a, b, temp;    
            printf("Enter value of a: ");
            scanf("%d", &a);    
            printf("Enter value of b: ");
            scanf("%d", &b);  
            printf("Before swapping: a = %d, b = %d\n", a, b);    
            // Swapping logic
            temp = a;
            a = b;
            b = temp;    
            printf("After swapping: a = %d, b = %d\n", a, b);       
           return 0;
        }

Result

        Enter value of a: 5
        Enter value of b: 4
        Before swapping: a = 5, b = 4
        After swapping: a = 4, b = 5

Explanation

* Any value can be used for a and b when running the above code. According to the above C code, we entered '5' for 'a' and '4' for 'b'. After the swapping, 'a' become '10'and 'b' become '5', which is reflected in the output.


Question 02

Check whether an entered number is negative, positive or zero.

C Code

            #include <stdio.h>
            int main ()
            {
                int number;             
                printf ("Enter a number:");
                Scanf ("%d", &number);
                if  (number > 0)
                {
                    printf ("number is positive.\n");
                }
                else if (number < 0)
                {
                    printf ("Number is negative.\n");
                }
                 else
                {
                    printf (" Number is zero.");
                }
                return 0;    
            }    


Result

            Enter a number : 1
            Number is positive.

            Enter a number : -5
            Number is negative.

            Enter a number : 0.1
            Number is zero.

Explanation

*Any number can be entered. When check the entered number using an "if, else if, else" construct:
  • if the  number is greater than "0", it prints that the number is positive.
  • else if the number is less than "0", it prints that number is negative.
  • else the number is not greater than "0", or not less than "0", it prints the number is zero.


Question 03

Check whether an entered year is leap year or not.

C Code

            #include <stdio.h>
            int main() 
            {
                int year;
                printf("Enter a year: ");
                scanf("%d", &year);
                // Leap year condition
                if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) 
                {
                    printf("%d is a leap year.\n", year);
                } 
                else 
                {
                    printf("%d is not a leap year.\n", year);
                }
                return 0;
            }

Result

            Enter a year: 2024
            2024 is a leap year.

            Enter a year: 2023
            2024 is not a leap year.

Explanation

*Any year can be entered. According to the leap year rules:
  • if the year is divisible by 400, it is a leap year.
  • if the year is divisible by 4, but not divisible by 100, it is also a leap year.
If the conditions are met, it prints that the entered year is a leap year; otherwise it prints that it is not a leap year.
When you run this program and enter  year, it will tell you whether the year is a leap year or not.


Question 04

Write a program that asks the user to type in two integer values at the terminal. Test these two numbers to determine if the first is evenly divisible by the second, and then display an appropriate message at the terminal.  


C Code

            #include <stdio.h>
            int main() 
            {
                int num1, num2;
                printf("Please enter two integer numbers: ");
                scanf("%d %d", &num1, &num2);
                if (num2 == 0) 
                {
                    printf("Division by zero is not allowed.\n");
                } 
                else if (num1 % num2 == 0) 
                {
                    printf("%d is evenly divisible by %d.\n", num1, num2);
                } 
                else 
                {
                    printf("%d is not evenly divisible by %d.\n", num1, num2);
                }
                return 0;
            }

Result

            Please enter two integer numbers: 2
            4
            2 is not evenly divisible by 4.

            Please enter two integer numbers: 4
            2
            4 is evenly divisible by 2.

            Please enter two integer values: 4
            0
            Error.

Explanation

*This program asks for two numbers. Any value can be used for these integer values. It the checks if the second number is zero. If it is, display an error. Otherwise, it checks if the first number is evenly divisible by the second number, it prints evenly divisible. Otherwise, it prints not evenly divisible.


Question 05


Write a program that accepts two integer values typed in by the user. Display the result of dividing the first integer by the second, to three-decimal-place accuracy. Remember to have the program check for division by zero.  

C Code

            #include <stdio.h>
            int main() 
            {
                int num1, num2;
                float result;
                printf("Enter two integer numbers: ");
                scanf("%d %d", &num1, &num2);
                if (num2 == 0) 
                {
                    printf("Error: Division by zero is not allowed.\n");
                } 
                else 
                {
                    result = (float)num1 / num2;
                    printf("%d divided by %d is %.3f.\n", num1, num2, result);
                }
                return 0;
            }

Result

            Enter two integer numbers: 0
            4
            0 divided by 4 is 0.000.

            Enter two integer numbers: 4
            0
            Error: Division by zero is not allowed.

            Enter two integer numbers: 3
            2
            3 divided by 2 is 1.500.

Explanation

*Any  value can be used. This program asks for two numbers and checks if the second number is zero. If it is, it displays error. Otherwise, it divides the first number by the second number, using floating point division to ensure accuracy and prints the result to three decimal places. 

Question 06

Write a program that takes an integer keyed in from the terminal and extracts and displays each digit of the integer in English. So, if the user types in 932, the program should display nine three two. Remember to display “zero” if the user types in just a 0.

C Code

            #include <stdio.h>
            void printDigitInEnglish(int digit) 
            {
                switch(digit) 
                {
                    case 0:
                        printf("zero");
                        break;
                    case 1:
                        printf("one");
                        break;
                    case 2:
                        printf("two");
                        break;
                    case 3:
                        printf("three");
                        break;
                    case 4:
                        printf("four");
                        break;
                    case 5:
                        printf("five");
                        break;
                    case 6:
                        printf("six");
                        break;
                    case 7:
                        printf("seven");
                        break;
                    case 8:
                        printf("eight");
                        break;
                    case 9:
                        printf("nine");
                        break;
                }
            }
            int main() 
            {
                int number;  
                printf("Enter an integer number: ");
                scanf("%d", &number);
                if (number == 0) 
                {
                    printf("zero\n");
                } 
                else 
                {
                    // Extract and print each digit in English
                   int reversedNumber = 0;
                   while (number > 0) 
                    {
                        int digit = number % 10;
                        reversedNumber = reversedNumber * 10 + digit;
                        number /= 10;
                    }
                    while (reversedNumber > 0) 
                    {
                        int digit = reversedNumber % 10;
                        printDigitInEnglish(digit);
                        /* Add space if there are more digits*/
                        if (reversedNumber / 10 > 0) 
                        {
                            printf(" ");
                        }
                        reversedNumber /= 10;
                    }
                    printf("\n");
                }
                return 0;
            }

Result

            Enter an integer number: 456
            four five six

            Enter an integer number: 70
            seven zero

            Enter an integer number: 9
            nine

Explanation

*This program first prompts the user to enter an integer number. It then check if the entered number is zero. If it ids, it print zero and terminates. Otherwise, it extracts each digit of the integer, reverses the order and prints each digit.

Question 07

Input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following: 
            a. Percentage >= 90% : Grade A 
            b. Percentage >= 80% : Grade B 
            c. Percentage >= 70% : Grade C 
            d. Percentage >= 60% : Grade D 
            e. Percentage >= 40% : Grade E 
            f. Percentage < 40% : Grade F

C Code

            #include <stdio.h>
            int main() 
            {
                float physics, chemistry, biology, mathematics, computer;
                float percentage;
                char grade;   
                /* Input marks of five subjects*/
                printf("Enter marks of Physics: ");
                scanf("%f", &physics);   
                printf("Enter marks of Chemistry: ");
                scanf("%f", &chemistry);    
                printf("Enter marks of Biology: ");
                scanf("%f", &biology);   
                printf("Enter marks of Mathematics: ");
                scanf("%f", &mathematics);   
                printf("Enter marks of Computer: ");
                scanf("%f", &computer);  
                /* Calculate percentage*/
                percentage = (physics + chemistry + biology + mathematics + computer) / 5.0;    
                /* Determine grade*/
                if (percentage >= 90) 
                {
                    grade = 'A';
                } 
                else if (percentage >= 80) 
                {
                    grade = 'B';
                } 
                else if (percentage >= 70) 
                {
                    grade = 'C';
                } 
                else if (percentage >= 60) 
                {
                    grade = 'D';
                } 
                else if (percentage >= 40) 
                {
                    grade = 'E';
                } 
                else 
                {
                    grade = 'F';
                }  
                /*Display percentage and grade*/
                printf("Percentage: %.2f%%\n", percentage);
                printf("Grade: %c\n", grade);
                return 0;
            }

Result

            Enter marks of Physics: 85
            Enter marks of Chemistry: 86
            Enter marks of Biology: 88
            Enter marks of Mathematics: 89
            Enter marks of Computer: 90
            Percentage: 87.60%
            Grade: B

Explanation

This program first prompts the user to enter marks of five subjects: Physics, Chemistry, Biology, Mathematics and Computer. It then calculates the percentage using the formula '(Physics + Chemistry + Biology + Mathematics + Computer)/5.0'. Based on the calculated percentage, it determines the grade according to the specified criteria and prints the percentage and grade.

Question 08

Input basic salary of an employee and calculate its Gross salary according to following: (note: HRA and DA are allowances) 
            a. Basic Salary <= 10000 : HRA = 20%, DA = 80% 
            b. Basic Salary <= 20000 : HRA = 25%, DA = 90% 
            c. Basic Salary > 20000 : HRA = 30%, DA = 95%  


C Code

            #include <stdio.h>
            int main() 
            {
                float basic salary, gross_salary;
                float hra, da;
                /*Input basic salary*/
                printf("Enter basic salary: ");
                scanf("%f", &basic_salary);  
                /*Calculate HRA and DA based on basic salary*/
                if (basic_salary <= 10000) 
                {
                    hra = 0.2 * basic_salary;
                    da = 0.8 * basic_salary;
                } 
                else if (basic_salary <= 20000) 
                {
                    hra = 0.25 * basic_salary;
                    da = 0.9 * basic_salary;
                } 
                else 
                {
                    hra = 0.3 * basic_salary;
                    da = 0.95 * basic_salary;
                } 
                /*Calculate gross salary*/
                gross_salary = basic_salary + hra + da;
                /*Display gross salary*/
                printf("Gross Salary: %.2f\n", gross_salary);
                return 0;
            }

Result

            Enter basic salary: 18000
            Gross Salary: 38700.00

Explanation

*This program first prompts the user to enter the basic alary of an employee. Then it calculates the house rent allowance(hra) and dearness allowance (da) based on the provided basic salary. After that, it calculates  the gross salary by adding the basic salary, hra and da. Finally it displays the gross salary.


Question 09

Write a program that acts as a simple “printing” calculator. The program should allow the user to type in expressions of the form number operator: The following operators should be recognized by the program: + - * / S E 
The S operator tells the program to set the “accumulator” to the typed-in number. 
The E operator tells the program that execution is to end. 
The arithmetic operations are performed on the contents of the accumulator with the number that was keyed in acting as the second operand. The following is a “sample run” showing how the program should operate: 

            Begin Calculations 
            10 S Set Accumulator to 10 
            = 10.000000 Contents of Accumulator 
            2 / Divide by 2 
            = 5.000000 Contents of Accumulator 
            55 - Subtract 55 
            -50.000000 
            100.25 S Set Accumulator to 100.25 
            = 100.250000 
            4 * Multiply by 4 
            = 401.000000 
            0 E End of program 
            = 401.000000 
            End of Calculations. 

Make certain that the program detects division by zero and also checks for unknown operators. 

C Code



Result



Explanation




Question 10

Input electricity unit charges and calculate total electricity bill according to the given condition: 

            a. For first 50 units Rs. 0.50/unit 
            b. For next 100 units Rs. 0.75/unit 
            c. For next 100 units Rs. 1.20/unit 
            d. For unit above 250 Rs. 1.50/unit 
            e. An additional surcharge of 20% is added to the bill 


C Code

            #include <stdio.h>
            int main() 
            {
                float units, bill = 0, surcharge;
                /*Input electricity units*/
                printf("Enter the electricity units consumed: ");
                scanf("%f", &units);
                /*Calculate bill according to given conditions*/
                if (units <= 50) 
                {
                    bill = units * 0.50;
                } 
                else if (units <= 150) 
                {
                    bill = 50 * 0.50;
                    bill += (units - 50) * 0.75;
                } 
                else if (units <= 250) 
                {
                    bill = 50 * 0.50 + 100 * 0.75;
                    bill += (units - 150) * 1.20;
                } 
                else 
                {
                    bill = 50 * 0.50 + 100 * 0.75 + 100 * 1.20;
                    bill += (units - 250) * 1.50;
                }
                /*Calculate surcharge*/
                surcharge = bill * 0.20;
                /*Add surcharge to the bill*/
                bill += surcharge;
                printf("Total electricity bill: Rs. %.2f\n", bill);
                return 0;
            }


Result

            Enter the electricity units consumed: 456
            Total electricity bill: Rs. 634.80

Explanation

* Any value can be entered for the electricity units consumed. This program takes input for the electricity units consumed and calculates the bill according to the given conditions. Then it calculates the surcharge (20% of the bill) and adds it to the total bill. Finally, it displays the total electricity bill.


Question 11

An envelope manufacturing company hires people to make envelopes. They provide all the raw material needed and pay at the following rates. Write a program to input the no of envelopes made and to calculate and print the amount due 

            Envelopes                 Rate 
            1-1000                       75 cents 
            1001-1500                 1 rupee 
            1501-2000                 1 rupee and 15 cents 
            2001-                         1 rupee and 25 cents 

C Code

            #include <stdio.h>
            int main() 
            {
                int num_envelopes;
                float amount_due = 0;
                /*Input the number of envelopes made*/
                printf("Enter the number of envelopes made: ");
                scanf("%d", &num_envelopes);
                /*Calculate amount due based on the number of envelopes*/
                if (num_envelopes <= 1000) 
                {
                    amount_due = num_envelopes * 0.75;
                } 
                else if (num_envelopes <= 1500) 
                {
                    amount_due = 1000 * 0.75 + (num_envelopes - 1000) * 1.0;
                } 
                else if (num_envelopes <= 2000) 
                {
                    amount_due = 1000 * 0.75 + 500 * 1.0 + (num_envelopes - 1500) * 1.15;
                } 
                else 
                {
                    amount_due = 1000 * 0.75 + 500 * 1.0 + 500 * 1.15 + (num_envelopes - 2000) * 1.25;
               }
                printf("Amount due: %.2f\n", amount_due);
                return 0;
            }


Result

            Enter the number of envelopes made: 1265
            Amount due: 1015.00

Explanation

*Any value can be entered for the number of envelop. This program takes input for the number of envelopes made and calculates the amount due based on the provided rates. Then it prints the amount due.

Question 12

Find the number of separate Notes and coins required to represent a given monetary value. E,g, 2700 required 1 ➡ 2000 note, 1➡ 500 note and 2➡100 notes.

C Code

            #include <stdio.h>
            int main() 
            {
                int amount, remaining_amount;
                int notes_2000, notes_500, notes_100, coins_50, coins_20, coins_10, coins_5, coins_2, coins_1;
                /*Input the monetary value*/
                printf("Enter the monetary value: ");
                scanf("%d", &amount);
                /*Calculate the number of each denomination*/
                notes_2000 = amount / 2000;
                remaining_amount = amount % 2000;
                notes_500 = remaining_amount / 500;
                remaining_amount %= 500;
                notes_100 = remaining_amount / 100;
                remaining_amount %= 100;
                coins_50 = remaining_amount / 50;
                remaining_amount %= 50;
                coins_20 = remaining_amount / 20;
                remaining_amount %= 20;
                coins_10 = remaining_amount / 10;
                remaining_amount %= 10;
                coins_5 = remaining_amount / 5;
                remaining_amount %= 5;
                coins_2 = remaining_amount / 2;
                remaining_amount %= 2;
               coins_1 = remaining_amount;
                /*Output the results*/
                printf("Number of notes and coins required:\n");
                printf("2000 notes: %d\n", notes_2000);
                printf("500 notes: %d\n", notes_500);
                printf("100 notes: %d\n", notes_100);
                printf("50 coins: %d\n", coins_50);
                printf("20 coins: %d\n", coins_20);
                printf("10 coins: %d\n", coins_10);
                printf("5 coins: %d\n", coins_5);
                printf("2 coins: %d\n", coins_2);
                printf("1 coins: %d\n", coins_1);
                return 0;
            }


Result

            Enter the monetary value: 25679
            Number of notes and coins required:
            2000 notes: 12
            500 notes: 3
            100 notes: 1
            50 coins: 1
            20 coins: 1
            10 coins: 0
            5 coins: 1
            2 coins: 2
            1 coins: 0

Explanation  

*Any monetary value can be entered. This program takes input for the  monetary value and the calculates the number of  each denomination of notes and coins needed to represent that value. Finally, it prints out the number of notes and coins required.


Question 13

Display Age, Birthday, and Gender using a given National Identity Card number. 

C Code



Result



Explanation






Friday, 23 February 2024

Tutorial 08

Tutorial 08

1. Write a program to evaluate the polynomial shows here.

3x 3 - 5x 2 + 6 for x = 2.55

Code
#include <stdio.h>

int main() {
    double x = 2.55;
    double result;

    // Evaluate the polynomial
    result = 3 * x * x * x - 5 * x * x + 6;

    // Print the result
    printf("The result of the polynomial for x = %.2f is: %.2f\n", x, result);

    return 0;
}

Result
The result of the polynomial for x = 2.55 is: 23.23

*In this program, we declare a variable x and initialize it with the value 2.55. Then, we use this value to evaluate the polynomial 3�3−5�2+6. Finally, we print the result to the console.

2. Write a program that evaluates the following expression and displays the results
(remember to use exponential format to display the result):
(3.31 × 10-8 × 2.01 × 10-7) / (7.16 × 10-6 + 2.01 × 10-8)  

Code
#include <stdio.h>

int main() {
    double numerator, denominator, result;

    // Evaluate the numerator and denominator separately
    numerator = (3.31e-8) * (2.01e-7);
    denominator = (7.16e-6) + (2.01e-8);

    // Check if the denominator is not zero
    if (denominator != 0) {
        // Evaluate the result
        result = numerator / denominator;

        // Display the result in exponential format
        printf("Result: %.2e\n", result);
    } else {
        printf("Error: Division by zero.\n");
    }

    return 0;
}

Result
Result: 9.27e-010

*In this program, we first calculate the numerator and denominator separately using the given values in exponential notation. Then, we ensure that the denominator is not zero to avoid division by zero error. If the denominator is nonzero, we proceed to calculate the result by dividing the numerator by the denominator and display the result in exponential format with two decimal places. If the denominator is zero, we display an error message indicating division by zero.

3. To round off an integer i to the next largest even multiple of another integer j, the
following formula can be used:

Next multiple = i + j - i % j

For example, to round off 256 days to the next largest number of days evenly divisible by
a week, values of i = 256 and j = 7 can be substituted into the preceding formula as
follows:

Next multiple = 256 + 7 - 256 % 7
= 256 + 7 - 4
= 259

Write a program to find the next largest even multiple for the following values of i and j:(Use keyboard to input values for i and j)
i                    j
365              7
12258        23
996              4

Code
#include <stdio.h>

int main() {
    int i, j, next_multiple;

    // Input values of i and j from the user
    printf("Enter the value of i: ");
    scanf("%d", &i);

    printf("Enter the value of j: ");
    scanf("%d", &j);

    // Calculate the next largest even multiple using the formula
    next_multiple = i + j - i % j;

    // Print the result
    printf("Next largest even multiple: %d\n", next_multiple);

    return 0;
}

Result
Enter the value of i: 256
Enter the value of j: 7
Next largest even multiple: 259

*In this program, the user is prompted to input the values of
� and �. Then, the program calculates the next largest even multiple using the provided formula ����_��������=�+�−�%�. Finally, the program displays the result to the user.

4. Write a program to input the radius of a sphere and to calculate the volume of the sphere.
Volume = 4/3*pi*radius3

Code
#include <stdio.h>
#include <math.h>

#define PI 3.14

int main() {
    double radius, volume;

    // Input the radius of the sphere
    printf("Enter the radius of the sphere: ");
    scanf("%lf", &radius);

    // Calculate the volume of the sphere
    volume = (4.0/3.0) * PI * pow(radius, 3);

    // Display the volume of the sphere
    printf("Volume of the sphere: %.2f\n", volume);

    return 0;
}

Result
Enter the radius of the sphere: 20
Volume of the sphere: 33493.33

  • We use standard input/output functions for user interaction (stdio.h) and mathematical functions like pow() for calculating the cube of the radius (math.h).

  • We define the value of pi as 3.14

  • The user inputs the radius of the sphere.

  • The program calculates the volume of the sphere using the formula for its volume.

  • Finally, it displays the calculated volume.

  • For a radius of 20, the program computes the volume of the sphere and displays the result.
5. 100 spherical ice (cubes) of a given radius are placed in a box of a given width, length and height. Calculate the height of the water level when the ice melts. Neglect the change in volume when ice converts to water.

Code
#include <stdio.h>

int main() {
    // Declare variables
    double radius, width, length, height, ice_volume, box_volume, water_height;
    int num_ice_cubes;

    // Input radius of the ice cubes
    printf("Enter the radius of the ice cubes: ");
    scanf("%lf", &radius);

    // Input dimensions of the box
    printf("Enter the width, length, and height of the box: ");
    scanf("%lf %lf %lf", &width, &length, &height);

    // Input number of ice cubes
    printf("Enter the number of ice cubes: ");
    scanf("%d", &num_ice_cubes);

    // Calculate the volume of one ice cube
    ice_volume = (4.0/3.0) * 3.14 * radius * radius * radius;

    // Calculate the total volume of all ice cubes
    ice_volume *= num_ice_cubes;

    // Calculate the volume of the box
    box_volume = width * length * height;

    // Calculate the volume occupied by water when ice melts
    water_height = (box_volume - ice_volume) / (width * length);

    // Display the height of the water level
    printf("Height of the water level when ice melts: %.2f\n", water_height);

    return 0;
}

Result
Enter the radius of the ice cubes: 30
Enter the width, length, and height of the box: 15,20,30
Enter the number of ice cubes: Height of the water level when ice melts: -1.#J

*This program takes input for the radius of the ice cubes, dimensions of the box (width, length, and height), and the number of ice cubes. Then, it calculates the height of the water level when the ice cubes melt, neglecting the change in volume when ice converts to water.

6. Write a program to input your mid term marks of a subject marked out of 30 and the final exam marks out of 100. Calculate and print the final results.
Final Result = Mid Term + 70% of Final Mark  

Code
#include <stdio.h>

int main() {
    int midterm_marks;
    float final_marks, final_result;

    // Input midterm marks
    printf("Enter your midterm marks (out of 30): ");
    scanf("%d", &midterm_marks);

    // Input final exam marks
    printf("Enter your final exam marks (out of 100): ");
    scanf("%f", &final_marks);

    // Calculate final result
    final_result = midterm_marks + (0.70 * final_marks);

    // Print final result
    printf("Your final result is: %.2f\n", final_result);

    return 0;
}

Result
Enter your midterm marks (out of 30): 28
Enter your final exam marks (out of 100): 76
Your final result is: 81.20

  • *In this program:
We use scanf to input the midterm marks and the final exam marks.
We calculate the final result by adding the midterm marks to 70% of the final exam marks.
Finally, we print the final result.
  • 7. Input the source file and destination file name as command line arguments and print the following message to standard output:
    “Copy the details in <file name 1> to <file name 2> at 23.59.59”
Code
#include <stdio.h> int main(int argc, char *argv[]) { // Check if the number of command-line arguments is correct if (argc != 3) { printf("Usage: %s <source_file> <destination_file>\n", argv[0]); return 1; } // Extract the file names from command-line arguments char *source_file = argv[1]; char *destination_file = argv[2]; // Print the message to standard output printf("Copy the details in %s to %s at 23.59.59\n", source_file, destination_file); return 0; }

Result
Usage: C:\Users\MY PC\Desktop\Text1.exe <source_file> <destination_file>

*This code checks if there are exactly three command-line arguments (including the program name itself). If the number of arguments is not correct, it prints a usage message. If the number of arguments is correct, it extracts the source and destination file names from the command-line arguments and prints the specified message to standard output.

8. Input the target rate as command line argument and compute the total commission as follows:
Total commission = ( total sale × 0.2 × target rate ) + cash flow.
Cash flow is a constant.

Code
#include <stdio.h>
#include <stdlib.h>

#define CASH_FLOW 1000 // Define the constant cash flow

int main(int argc, char *argv[]) {
    // Check if the correct number of command-line arguments is provided
    if (argc != 2) {
        printf("Usage: %s <target_rate>\n", argv[0]);
        return 1;
    }

    // Convert the command-line argument (target_rate) to a float
    float target_rate = atof(argv[1]);

    // Check if the target rate is a positive number
    if (target_rate <= 0) {
        printf("Error: Target rate must be a positive number.\n");
        return 1;
    }

    // Example value for total sale (you can change it as needed)
    float total_sale = 5000;

    // Calculate the total commission
    float total_commission = (total_sale * 0.2 * target_rate) + CASH_FLOW;

    // Print the total commission
    printf("Total commission: %.2f\n", total_commission);

    return 0;
}

*This code checks if the correct number of command-line arguments is provided. It converts the target rate provided as a command-line argument to a float and checks if it's a positive number. Then it calculates the total commission using the given formula and prints the result.

Tutorial 12

Functions  Question 01 Display all prime numbers between two Intervals using a function.   C Code                #include <stdio.h>   ...