/*
This is the third lab of Lab EE107
The purpose of this lab is to understand the difference in storage for typecasts and the basic datatype conversions in C
The purpose is to create the code and free of syntax and grammatical errors
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: Feb 6, 2024.
    */

#include <stdio.h>

int main(void) {
    // Defining some uninitialized variables to store results
    float floatnumber1_EU = 123.125;
    float floatnumber2_EU, floatnumber3_EU, floatnumber4_EU;
    float floatnumber5_EU, floatnumber6_EU;  // Added missing variable floatnumber6_EU

    int intnumber1_EU, intnumber2_EU = -150, intnumber3_EU, intnumber4_EU;
    int intnumber5_EU;

    // *****************floating to integer conversion*******************
    // Method I: Directly assign a float type to an int type number 
    intnumber1_EU = floatnumber1_EU;
    printf("First printf: %f assigned to an int produces %i\n\n", floatnumber1_EU, intnumber1_EU);

    // *****************floating to integer conversion*******************
    // Method II: Directly assign a float type to an int type number 
    intnumber3_EU = (int)floatnumber1_EU;
    printf("Second printf: Type cast the float type number %f assigned to an int produces %i\n\n", floatnumber1_EU, intnumber3_EU);

    // *****************integer to floating conversion*******************
    // Method III: Directly assign an int type to a float type number 
    floatnumber3_EU = intnumber2_EU;
    printf("Third printf: %i assigned to an int produces %f\n\n", intnumber2_EU, floatnumber3_EU);

    // *****************floating to integer conversion*******************
    // Method IV: Directly assign an int type to a float type number 
    floatnumber4_EU = (float)intnumber2_EU;
    printf("Fourth printf: Type cast the int type number %i assigned to a float produces %f\n\n", intnumber2_EU, floatnumber4_EU);

    // *****************floating-point arithmetic*******************
    floatnumber5_EU = intnumber2_EU / 100;
    printf("Fifth printf: %i divided by 100 produces %f\n\n", intnumber2_EU, floatnumber5_EU);

    // *****************floating-point arithmetic*******************
    floatnumber6_EU = (float)intnumber2_EU / 100;
    printf("Sixth printf: %i divided by 100 produces %f\n\n", intnumber2_EU, floatnumber6_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: