Part 2 You will write a program that takes a user-supplied integer and prints it to stdout in four different formats: signed decimal, unsigned decimal, hexadecimal, and binary. Your main method will read a signed decimal integer from the user through stdin, and then print the number in the four formats. You may assume that the user will enter a valid integer, so no error checking is necessary. Your Makefile should generate an executable called convert. Sample Executions $ ./convert Enter an integer : 1 signed decimal : 1 unsigned decimal: 1 hexadecimal 1 : 0000 0000 0000 0000 0000 0000 0000 0001 binary $ ./convert Enter an intener. -1 hes (33 sloc) 1.9 KB unsigned decimal: 4294967295 hexadecimal : ffffffff binary : 1111 1111 1111 1111 1111 1111 1111 1111 $ ./convert Enter an integer 256 signed decimal : 256 unsigned decimal: 256 hexadecimal binary : 100 : 0000 0000 0000 0000 0000 0001 0000 0000 <> Raw Blame Note that your program must behave EXACTLY the same as the sample executions above. This means that the strings, ordering, and spacing must be the same. Requirements/Tips • The only libraries you can include are stdio.h and stdlib.h. Any other libraries you include will be removed before we test you code. You must use putc to print the binary representation. Use man 3 putc for more information. o For example, to write the character '1' to stdout, use putc('1', stdout) • To convert from decimal to binary, you must use bitwise or bit shifting operations. You must not use the mod (%) operator. • You must use scanf("%d", &x) to read an integer inputted through stdin (into a variable x). Feel free to name the variable however you wish. • There is never a space after the last readable character on a line of output. There is, however, a new-line character after the last binary digit on the last line.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

Hello, I need help with this C program

 

 

Part 2
You will write a program that takes a user-supplied integer and prints it to stdout in four different formats: signed decimal, unsigned
decimal, hexadecimal, and binary.
Your main method will read a signed decimal integer from the user through stdin, and then print the number in the four formats. You
may assume that the user will enter a valid integer, so no error checking is necessary.
Your Makefile should generate an executable called convert
Sample Executions
$ ./convert
Enter an integer : 1
signed decimal : 1
unsigned decimal: 1
hexadecimal
: 1
binary
: 0000 0000 0000 0000 0000 0000 0000 0001
$ ./convert
Enter an integer. -1
nes (33 sloc) 1.9 KB
unsigned decimal: 4294967295
hexadecimal
: ffffffff
: 1111 1111 1111 1111 1111 1111 1111 1111
binary
$ ./convert
Enter an integer : 256
signed decimal : 256
unsigned decimal: 256
hexadecimal
binary
: 100
: 0000 0000 0000 00 000 0001 000 0000
Raw Blame
• You must use putc to print the binary representation. Use man 3 putc for more information.
o For example, to write the character '1' to stdout, use putc('1', stdout)
Note that your program must behave EXACTLY the same as the sample executions above. This means that the strings, ordering, and
spacing must be the same.
Requirements/Tips
• The only libraries you can include are stdio.h and stdlib.h. Any other libraries you include will be removed before we test your
code.
• To convert from decimal to binary, you must use bitwise or bit shifting operations. You must not use the mod (%) operator.
• You must use scanf("%d", &x) to read an integer inputted through stdin (into a variable x). Feel free to name the variable
however you wish.
C
• There is never a space after the last readable character on a line of output. There is, however, a new-line character after the last
binary digit on the last line.
Transcribed Image Text:Part 2 You will write a program that takes a user-supplied integer and prints it to stdout in four different formats: signed decimal, unsigned decimal, hexadecimal, and binary. Your main method will read a signed decimal integer from the user through stdin, and then print the number in the four formats. You may assume that the user will enter a valid integer, so no error checking is necessary. Your Makefile should generate an executable called convert Sample Executions $ ./convert Enter an integer : 1 signed decimal : 1 unsigned decimal: 1 hexadecimal : 1 binary : 0000 0000 0000 0000 0000 0000 0000 0001 $ ./convert Enter an integer. -1 nes (33 sloc) 1.9 KB unsigned decimal: 4294967295 hexadecimal : ffffffff : 1111 1111 1111 1111 1111 1111 1111 1111 binary $ ./convert Enter an integer : 256 signed decimal : 256 unsigned decimal: 256 hexadecimal binary : 100 : 0000 0000 0000 00 000 0001 000 0000 Raw Blame • You must use putc to print the binary representation. Use man 3 putc for more information. o For example, to write the character '1' to stdout, use putc('1', stdout) Note that your program must behave EXACTLY the same as the sample executions above. This means that the strings, ordering, and spacing must be the same. Requirements/Tips • The only libraries you can include are stdio.h and stdlib.h. Any other libraries you include will be removed before we test your code. • To convert from decimal to binary, you must use bitwise or bit shifting operations. You must not use the mod (%) operator. • You must use scanf("%d", &x) to read an integer inputted through stdin (into a variable x). Feel free to name the variable however you wish. C • There is never a space after the last readable character on a line of output. There is, however, a new-line character after the last binary digit on the last line.
Part 1
You will implement the following three methods to find the GCD of two numbers. You may not change any of these method
signatures.
int gcd_iterative(int m, int n);
int gcd_recursive(int m, int n);
int main(int argc, char **argv);
In both gcd_iterative and gcd_recursive, you will implement Euclid's method (feel free to search for the algorithm on Google). The
iterative version will use a while loop, while the recursive will, of course, use recursion.
The function header for gcd_iterative can be found in iterative.h and the function header for gcd_recursive can be found in
recursive.h. The function definitions must be in iterative.c and recursive.c respectively (which you will create).
The main method in gcd.c will parse the command line arguments and call both gcd_iterative and gcd_recursive. Don't forget
that gcd(m, n) is equivalent to gcd ([m], [n]) so you should never return a negative value.
If more than or less than two command line arguments are provided, you should print the following error message to stderr then exit
in failure.
Usage: ./gcd <integer m> <integer n>
If two command line arguments are provided, you may assume that they will be valid integers. If the two integers are 0, you should
print the following message to stdout then exit in success.
gcd (0, 0) = undefined
Otherwise, your output should match the sample executions below. Then, you should exit in success.
Your Makefile should generate an executable called gcd .
Sample Executions
nes (41 sloc)
Recursive: gca(24, 12) = 12
$ ./gcd -2 10
2.6 KB
Iterative: gcd (-2, 10) = 2
Recursive: gcd (-2, 10) = 2
$ ./gcd 0 0
gcd(0, 0) = undefined
$ ./gcd 1 1 1
Usage: ./gcd <integer m> <integer n>
<>
U
Raw
• gcd.c may not include any source files directly. (i.e. you cannot do #include "recursive.c")
• You may use the abs library function to find the absolute value of an int. Use man 3 abs for more information.
• You will need to use atoi to convert from char * to int. Use man 3 atoi for more information.
Blame
Note that your program must behave EXACTLY the same as the sample executions above. This means that the strings, ordering, and
spacing must be the same.
Requirements/Tips
The only libraries you can include are stdio.h and stdlib.h. Any other libraries you include will be removed before we test your
code.
• Use the EXIT_SUCCESS and EXIT_FAILURE macros for returning from the main function of gcd.c.
• You are required to add header guards (conditional compilation directives) to each header file. (recursive.h and iterative.h).
Transcribed Image Text:Part 1 You will implement the following three methods to find the GCD of two numbers. You may not change any of these method signatures. int gcd_iterative(int m, int n); int gcd_recursive(int m, int n); int main(int argc, char **argv); In both gcd_iterative and gcd_recursive, you will implement Euclid's method (feel free to search for the algorithm on Google). The iterative version will use a while loop, while the recursive will, of course, use recursion. The function header for gcd_iterative can be found in iterative.h and the function header for gcd_recursive can be found in recursive.h. The function definitions must be in iterative.c and recursive.c respectively (which you will create). The main method in gcd.c will parse the command line arguments and call both gcd_iterative and gcd_recursive. Don't forget that gcd(m, n) is equivalent to gcd ([m], [n]) so you should never return a negative value. If more than or less than two command line arguments are provided, you should print the following error message to stderr then exit in failure. Usage: ./gcd <integer m> <integer n> If two command line arguments are provided, you may assume that they will be valid integers. If the two integers are 0, you should print the following message to stdout then exit in success. gcd (0, 0) = undefined Otherwise, your output should match the sample executions below. Then, you should exit in success. Your Makefile should generate an executable called gcd . Sample Executions nes (41 sloc) Recursive: gca(24, 12) = 12 $ ./gcd -2 10 2.6 KB Iterative: gcd (-2, 10) = 2 Recursive: gcd (-2, 10) = 2 $ ./gcd 0 0 gcd(0, 0) = undefined $ ./gcd 1 1 1 Usage: ./gcd <integer m> <integer n> <> U Raw • gcd.c may not include any source files directly. (i.e. you cannot do #include "recursive.c") • You may use the abs library function to find the absolute value of an int. Use man 3 abs for more information. • You will need to use atoi to convert from char * to int. Use man 3 atoi for more information. Blame Note that your program must behave EXACTLY the same as the sample executions above. This means that the strings, ordering, and spacing must be the same. Requirements/Tips The only libraries you can include are stdio.h and stdlib.h. Any other libraries you include will be removed before we test your code. • Use the EXIT_SUCCESS and EXIT_FAILURE macros for returning from the main function of gcd.c. • You are required to add header guards (conditional compilation directives) to each header file. (recursive.h and iterative.h).
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education