/* This is the eleventh lab of Lab EE107
The purpose of this lab for a function that calculates and returns the
absolute value of a number, and uses this function to do calculations.

Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 9th, 2024.
*/
#include <stdio.h>

// Function to calculate the absolute value of a number
float absolute_value_EU(float num_EU) {
    if (num_EU < 0)
        return -num_EU;
    else
        return num_EU;
}

int main() {
    // Define numbers
    float num1_EU = -10.5;
    float num2_EU = 5.5;
    float abs_num1_EU, abs_num2_EU;

    // Calculate absolute values
    abs_num1_EU = absolute_value_EU(num1_EU);
    abs_num2_EU = absolute_value_EU(num2_EU);

    // Use absolute values for calculations
    float sum_abs_EU = abs_num1_EU + abs_num2_EU;
    float difference_abs_EU = abs_num1_EU - abs_num2_EU;
    float product_abs_EU = abs_num1_EU * abs_num2_EU;

    // Display results
    printf("Absolute value of %.2f is %.2f\n", num1_EU, abs_num1_EU);
    printf("Absolute value of %.2f is %.2f\n", num2_EU, abs_num2_EU);
    printf("Sum of absolute values: %.2f\n", sum_abs_EU);
    printf("Difference of absolute values: %.2f\n", difference_abs_EU);
    printf("Product of absolute values: %.2f\n", product_abs_EU);

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: