tudent. He asked for help on conversion of decimal to Your 1. #include 0 ;i++) { int rem - n % 2; binaryNun - ren + binaryNun*10; n-n/ 2; } 13 ong decBin(int n); 14 Preturns the binary equivalent of n. Use of built in function that will automatically convert decimal to binary is not allo ved. 15 Your 16 Output 17 18 Expected 19 10000 Output oid display(long binary); Long binary - 0; 20 21 uhila ChingmdMum

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
Question

Program C

 

Custom Input
Output
Test Cases
Executions
I am a doctor and my son's a freshman Computer Science
decBin.c X
> +
main.c
decBin.h
student. He asked for help on conversion of decimal to
Your
binary. Can you help me to do a program that automatically
#include <stdio.h>
Output
110111
int getNum(){
int num;
printf("");
scanf("%d", &num);
return num;
}
converts decimal to binary?
You have been tasked to make a program that will
Expected
Output
4
automatically convert decimal digits to binary digits. This is
110111
5
great! You could help someone to learn more things.
6
7
Implement the following functions:
8
long decBin(int n)
O Test Case 2
10
{
int getNum();
/*accepts input from the user.*/
long binaryNum = 0;
11
Input
12
16
for (int i=0; n > 0 ;i++)
{
int rem = n % 2;
binaryNum = rem + binaryNum*10;
n = n / 2;
}
13
long decBin(int n);
/*returns the binary equivalent of n. Use of built in function
s that will automatically convert decimal to binary is not allo
14
15
Your
1
16
Output
wed.
17
*/
18
Expected
19
10000
Output
long binary = 0;
while (binaryNum != 0)
{
int rem = binaryNum % 10;
binary = binary * 10 + rem;
binaryNum /= 10;
}
return binary;
}
void display(long binary);
/*displays the binary equivalent*/
21
22
23
Note:
24
O Test Case 3
1. Use only for loop.
2. You are not allowed to edit main.c and decBin.h. Add
26
Input
8
27
another file that contains the implementation.
28
29
Your
void display(long binary)
{
printf("%ld", binary);
}
30
1.
Output
31
32
Score: 0/10
Expected
33
Output
1000
Transcribed Image Text:Custom Input Output Test Cases Executions I am a doctor and my son's a freshman Computer Science decBin.c X > + main.c decBin.h student. He asked for help on conversion of decimal to Your binary. Can you help me to do a program that automatically #include <stdio.h> Output 110111 int getNum(){ int num; printf(""); scanf("%d", &num); return num; } converts decimal to binary? You have been tasked to make a program that will Expected Output 4 automatically convert decimal digits to binary digits. This is 110111 5 great! You could help someone to learn more things. 6 7 Implement the following functions: 8 long decBin(int n) O Test Case 2 10 { int getNum(); /*accepts input from the user.*/ long binaryNum = 0; 11 Input 12 16 for (int i=0; n > 0 ;i++) { int rem = n % 2; binaryNum = rem + binaryNum*10; n = n / 2; } 13 long decBin(int n); /*returns the binary equivalent of n. Use of built in function s that will automatically convert decimal to binary is not allo 14 15 Your 1 16 Output wed. 17 */ 18 Expected 19 10000 Output long binary = 0; while (binaryNum != 0) { int rem = binaryNum % 10; binary = binary * 10 + rem; binaryNum /= 10; } return binary; } void display(long binary); /*displays the binary equivalent*/ 21 22 23 Note: 24 O Test Case 3 1. Use only for loop. 2. You are not allowed to edit main.c and decBin.h. Add 26 Input 8 27 another file that contains the implementation. 28 29 Your void display(long binary) { printf("%ld", binary); } 30 1. Output 31 32 Score: 0/10 Expected 33 Output 1000
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Datatypes
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