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
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
ADVERTISEMENT