Question

WRITE THE FOLLOWING IN C (NOT C++ OR JAVA)

1o.9 (Using Unions) Create union floatingPoint with members float f, double d and long double x. Write a program that inputs values of rype float, double and long double and stores the float, a double and a long double. Do the values always print correctly? Note: The long double result will vary depending on the system (Windows, Linux, MAC) you use. So values in union variables of type union floatingPoint. Each union variable should be printed as a do not be concern if you are not getting the correct answer. Input must be same for all cases for comparison. Enter data for type float:234.567 Breakdown of the element in the union float 234.567001 double 0.00000O long double 0.GOOOO0 Breakdown in float e0000000 double 436a9127 long double 22fde0 hex Enter data for type double :234.567 Breakdown of the element in the union float -788598326743269380.G0G00O double 234.5670G0 long double 0.GOOOO0 Breakdown in hex float 0 double dd2f1aa0 long double 22fde0 Enter data for type long double:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include
#include

union floatingPoint {
float floatNum;
double doubleNum;
long double longDoubleNum;
};

int main() {
union floatingPoint f;

printf("Enter data for type float: ");
scanf("%f", &f.floatNum);

printf("\nfloat %f ", f.floatNum);
printf("\ndouble %f ", f.doubleNum);
printf("\nlong double %Lf ", f.longDoubleNum);

printf("\n\nBreakdown in Hex");
printf("\nfloat in hex %x ", f.floatNum);
printf("\ndouble in hex %x ", f.doubleNum);
printf("\nlong double in hex %Lx ", f.longDoubleNum);

printf("\n\nEnter data for type double: ");
scanf("%lf", &f.doubleNum);

printf("float %f ", f.floatNum);
printf("\ndouble %f ", f.doubleNum);
printf("\nlong double %Lf ", f.longDoubleNum);

printf("\n\nBreakdown in Hex");
printf("\nfloat in hex %x ", f.floatNum);
printf("\ndouble in hex %x ", f.doubleNum);
printf("\nlong double in hex %Lx ", f.longDoubleNum);

printf("\n\nEnter data for type long double: ");
scanf("%Lf", &f.longDoubleNum);

printf("float %f ", f.floatNum);
printf("\ndouble %f ", f.doubleNum);
printf("\nlong double %Lf ", f.longDoubleNum);

printf("\n\nBreakdown in Hex");
printf("\nfloat in hex %x ", f.floatNum);
printf("\ndouble in hex %x ", f.doubleNum);
printf("\nlong double in hex %Lx ", f.longDoubleNum);

return 0;
}

Add a comment
Know the answer?
Add Answer to:
WRITE THE FOLLOWING IN C (NOT C++ OR JAVA) 1o.9 (Using Unions) Create union floatingPoint with members float f, doubl...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • WRITE THE FOLLOWING IN C (NOT C++ OR JAVA) Problem 6A (5 points 10.8 (Using Unions) Create union integer with members...

    WRITE THE FOLLOWING IN C (NOT C++ OR JAVA) Problem 6A (5 points 10.8 (Using Unions) Create union integer with members char c, short s, int i and long b. Write a program that inputs values of type char, short, int and long and stores the values in union variables of type union integer. Each union variable should be printed as a char, a short, an int and a long. Do the values always print correctly? Sample input/output. To print...

  • In "C" Language (Using Unions) Create union integer with members char c, short s, int i and long b. Write a program th...

    In "C" Language (Using Unions) Create union integer with members char c, short s, int i and long b. Write a program that inputs values of type char, short, int and long and stores the values in union variables of type union integer. Each union variable should be printed as a char, a short, an int and a long. Do the values always print correctly:? Sample input/output. To print in hexadecimal, use %x as the formatter. Input must be same...

  • Programing C Create union integer with members char c, short s, int i and long l....

    Programing C Create union integer with members char c, short s, int i and long l. Write a program that inputs values of type char, short, int and long and stores the values in union variables of type union integer. Each union variable should be printed as a char, a short, an int and a long. Make sure that the correct values are printed as shown below in the example An example interaction: Enter a char: A The char is:...

  • (Using Unions) Create union integer with members char c, short s, int i and long b

    This is from chapter 10 ex 10.8 in c how to program 6th ed deitelWrite a program that inputs the values of type char, short, int, and long and stores the values in union variables of type union integer. Each union variable should beprinted as a char, a short, an int and a long. D the values always print correctly?. Also create a flow chart or psuedocode of the program .

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Using Unix/Linux Command line in terminal and C programming. (b) Write a basic C program contained...

    Using Unix/Linux Command line in terminal and C programming. (b) Write a basic C program contained in a1q4.c and perform the following tasks in your program’s main() function: (8 marks) • Declare and initialize at least one variable of these types: char, int, unsigned int, float, double and long double. When initializing your variables, ensure the constants you use are of the same type as your variable. See the “Constants” section of Topic 7 for more information. • Use printf(3)...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called...

    Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...

  • C++ Question Question 3 [43] The Question: You are required to write a program for an...

    C++ Question Question 3 [43] The Question: You are required to write a program for an Online Tutoring Centre to determine the weekly rate depending on the number of sessions the students attend and then to calculate total revenue for the center. The Online Tutoring Centre charges varying weekly rates depending on the on grade of the student and number of sessions per week the student attends as shown in Table 1 below. Grade 8 9 Session 1 75 80...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT