Question

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 hexadecimal, use 96x as the formatter. Input must be same for all cases for comparison Enter data for type char:8 Breakdown of the element in the union char 8 short 56 int 56 long 56 Breakdown in hex char 3!8 short 38 int 38 long 38 Enter data for type short:8 Breakdown of the element in the union cha short 8 int 8 long 8 Breakdown in hex char 8 short t8 int 8 long 8 Enter data for type int:

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

code.c

#include

union integer{
char c;
short s;
int i;
long b;
};

void breakdown(union integer myunion){
printf("Breakdown of the elements in union \n");
printf("char : %c\n",myunion.c);
printf("short : %d\n",myunion.s);
printf("int : %d\n",myunion.i);
printf("long : %d\n",myunion.b);
printf("\n\n");
printf("breakdown in hex\n");
printf("char : %x\n",myunion.c);
printf("short : %x\n",myunion.s);
printf("int : %x\n",myunion.i);
printf("long : %x\n",myunion.b);
  
}

int main(){
  
union integer myunion;
printf("Enter data for type char : ");
scanf("%c",&myunion.c);
breakdown(myunion);
printf("Enter data for type short : ");
scanf("%d",&myunion.s);
breakdown(myunion);
printf("Enter data for type int : ");
scanf("%d",&myunion.i);
breakdown(myunion);
printf("Enter data for type long : ");
scanf("%d",&myunion.b);
breakdown(myunion);  


return 0;
}

SAMPLE OUTPUT:

input a clear gcc version 4.6.3 Enter data for type char 8 Breakdown of the elements in union char 8 short 56 int 56 long 56

PLEASE RATE ! !

Thanks !

Add a comment
Know the answer?
Add Answer to:
WRITE THE FOLLOWING IN C (NOT C++ OR JAVA) Problem 6A (5 points 10.8 (Using Unions) Create union integer with members...
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
  • 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...

  • WRITE THE FOLLOWING IN C (NOT C++ OR JAVA) 1o.9 (Using Unions) Create union floatingPoint with members float f, doubl...

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

  • (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 .

  • Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code...

    Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code for 8-bit signed array, 16-bit unsigned array, 16-bit signed array, 32-bit signed array and 32-bit signed array. 2) Fill in all the blanks in Table 1 using your completed code, following the hints provided within the table. 3) Fill in all the blanks in Table 2 using your completed code, following the hints provided within the table. C++ Program #include <stdio.h> #include <iostream> int...

  • use java and write in text a. Rewrite the following code segment using if statements. Assume...

    use java and write in text a. Rewrite the following code segment using if statements. Assume that grade has been declared as of type char. char grade= 'B';; switch (grade) { case 'A': System.out.println("Excellent"); break case 'B': System.out.println("Good"); default: System.out.println("you can do better”); } - b. write Java code that inputs an integer and prints each of its digit followed by ** e.gif the integer is 1234 then it should print 1**2**3**4 e.g. if the integer is 85 then it...

  • in java Original: Sound Visualization Write a program that uses StdAudio and Picture to create an...

    in java Original: Sound Visualization Write a program that uses StdAudio and Picture to create an interesting two-dimensional color visualization of a sound file while it is playing. Be creative! Additional Notes: double[] data = StdAudio.read(<filename>); -> Takes a sound file and store it as a 2D array of real numbers. Picture pic = new Picture(300,200); -> Creates a picture 300 pixels wide and 200 pixels high Color c= new Color(<red>,<green>,<blue>); -> Each value of <red>, <green>, <blue> is between...

  • Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and...

    Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and implementation HighArray class and note the attributes and its methods.    Create findAll method which uses linear search algorithm to return all number of occurrences of specified element. /** * find an element from array and returns all number of occurrences of the specified element, returns 0 if the element does not exit. * * @param foundElement   Element to be found */ int findAll(int...

  • Need this in C Code is given below e Dots l lah dit Problem 1. (30...

    Need this in C Code is given below e Dots l lah dit Problem 1. (30 points) Fre bendord.cto obtain the free in decimal representation For ATY. this problem we complete the code in i tive long inte ens (W written the following positive long term 123, 40, 56, 7, 8, 9, 90, 900 the frequencies of all the digits are: 0:4, 1:1, 2:1, 3:1, 4:1, 5:1, 6:1, 7: 1. 8: 1.9: 3 In this example, the free ency of...

  • C++ Program - Arrays- Include the following header files in your program:     string, iomanip, iostream Suggestion:...

    C++ Program - Arrays- Include the following header files in your program:     string, iomanip, iostream Suggestion: code steps 1 thru 4 then test then add requirement 5, then test, then add 6, then test etc. Add comments to display assignment //step 1., //step 2. etc. This program is to have no programer created functions. Just do everything in main and make sure you comment each step. Create a program which has: 1. The following arrays created:                 a. an array...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

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