
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Fill in the code
![#include <stdio.h>
#include <math.h> // This library is for math operation
int main(){
int n; //number of cases
int x; //number in base 10
scanf("%i", ??);
// Loop for the number of cases
while (??){
scanf("%i", &??);
int size = log2(??) + 1; //size of the array. log2: logarithm base 2
int bin[??]; // this array will contain the digits of the binary number
// Convert from base 10 to base 2
int i = ??;
while (??){
bin[i]
x /= 2; // update x
= x%2; // reminder
??;
}
// Print binary number
i = ??;
while (??){
printf("%i", bin[i]);
??;
}
printf("\n");
??;
return 0;
}](https://content.bartleby.com/qna-images/question/b4fbdee7-4dd6-4b70-b473-f3d2f2c3fe84/02e85b27-dc23-498c-bca7-4976842734c4/f057kkt_thumbnail.png)
Transcribed Image Text:#include <stdio.h>
#include <math.h> // This library is for math operation
int main(){
int n; //number of cases
int x; //number in base 10
scanf("%i", ??);
// Loop for the number of cases
while (??){
scanf("%i", &??);
int size = log2(??) + 1; //size of the array. log2: logarithm base 2
int bin[??]; // this array will contain the digits of the binary number
// Convert from base 10 to base 2
int i = ??;
while (??){
bin[i]
x /= 2; // update x
= x%2; // reminder
??;
}
// Print binary number
i = ??;
while (??){
printf("%i", bin[i]);
??;
}
printf("\n");
??;
return 0;
}
![Task 1: Defining an array
This task consists in converting a number from base 10 to base 2. The user will input the n
integer numbers. The program must return the n binary numbers.
Step 1: Divide the given number 13 repeatedly by 2 until
you get '0'as the quotient
13 + 2 = 6 (Remainder 1)
6 + 2 = 3 (Remainder 0)
3 + 2 = 1 (Remainder 1)
1 + 2 = 0 (Remainder 1)
Step 2: Write the remainders in the reverse 1 10 1
order
:. 1310
= 1101,
(Decimal)
(Binary)
10
arr I4] =
1
1.2° t0-2*t 1.2+ O•2"= 10
Hint:
You must store each digit of the binary number in an array and then print them. The length of
the array must be equal to the number of digits of the binary number.
DO NOT USE ANY BUILT-IN FUNCTION](https://content.bartleby.com/qna-images/question/b4fbdee7-4dd6-4b70-b473-f3d2f2c3fe84/02e85b27-dc23-498c-bca7-4976842734c4/poppms_thumbnail.png)
Transcribed Image Text:Task 1: Defining an array
This task consists in converting a number from base 10 to base 2. The user will input the n
integer numbers. The program must return the n binary numbers.
Step 1: Divide the given number 13 repeatedly by 2 until
you get '0'as the quotient
13 + 2 = 6 (Remainder 1)
6 + 2 = 3 (Remainder 0)
3 + 2 = 1 (Remainder 1)
1 + 2 = 0 (Remainder 1)
Step 2: Write the remainders in the reverse 1 10 1
order
:. 1310
= 1101,
(Decimal)
(Binary)
10
arr I4] =
1
1.2° t0-2*t 1.2+ O•2"= 10
Hint:
You must store each digit of the binary number in an array and then print them. The length of
the array must be equal to the number of digits of the binary number.
DO NOT USE ANY BUILT-IN FUNCTION
Expert Solution

arrow_forward
Step 1 ::
- We need to complete the code after filling the spaces.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images

Knowledge Booster
Similar questions
- Which scope function is used when the result of the block is not needed? run O apply also letarrow_forwardPlease code using C++ and only use the header <iostream>. Any use of additional headers will not be accepted. Thank you.arrow_forwardHi, I need help with this question. It is about C programming. Thank youarrow_forward
- (B) Write a M-File to calculate the square root of each element of the vector v=16,10,34. Display the results in the form: "The square root is v" with a total of 6 digits with 2 digits after the decimal point.arrow_forwardCan you use Python programming language to to this question? Thanksarrow_forwardDo you know if you can paste the code in eclpise format?arrow_forward
- ) Use 30 files you generated in part 1 of this assignment to give as the input to your three sorting functions and measure the duration of each function. Comment the statements you used to print the sorted array after each sorting function, as you need to measure only the time taken to sort. The output of each sort is the time taken in milliseconds to sort the given unsorted array. You can use "#include <chrono>" or "#include<time.h>" to measure the duration of a function in C++. While measuring the time you only need to measure the time taken by each sorting algorithm to convert the unsorted array into a sorted array. Note: The additional time taken, such as to construct your input array and to print your sorted array to console should not be included while measuring the duration of the sort.arrow_forwardPROBLEM: Create a program that will ask to fill in two square matrices and perform matrix multiplication. Output the resulting matrix in proper format. SPECIFICATIONS that you need to follow: - The maximum size of the square matrices is 10x10. Matrices 1 and 2 should have the same dimensions. - You may only use the codes that we studied under our lectures - All lines of codes should have a comment. - Save your cpp file as Surname_FE (Example: Pangaliman_FE.cpp) TEST CASES: If a user inputs n = 2: Input: Input dimension (nxn) of the matrix, n = 2Input Matrix 1 elements: 1 2 3 4Input Matrix 2 elements: 5 6 7 8 Result: Resultant matrix: 19 22 43 50 If a user inputs n = 10: Input: Input dimension (nxn) of the matrix, n = 10 Input Matrix 1 elements: -35 54 64 31 45 -12 17 -31 -19 -78 -35 54 3 -10 -11 90 -41 31 -30 0 22 -53 21 -13 -64 32 -70 57 58 86 -77 30 73 24 -77 -90 -26 85 48 -47 -96 58 70 -59 82 -97 43 51 45 62 63 40 67 42 52 -78 -69…arrow_forward31. Find the sum of all 2-digit positive integers present in the array given below, and print the sum in the output. [24, 678, −127, 12, 0, 78, -9999, 91, 45, -10] Write your code in C++.arrow_forward
- C++ PLEASE HELP MUST MATCH OUTPUT IN PICS In this lab, you're going to be working with partially filled arrays that are parallel with each other. That means that the row index in multiple arrays identifies different pieces of data for the same person. This is a simple payroll system that just calculates gross pay given a set of employees, hours worked for the week and hourly rate. Parallel Arrays First, you have to define several arrays in your main program employee names for each employee hourly pay rate for each employee total hours worked for each employee gross pay for each employee You can use a global SIZE of 50 to initialize these arrays Second, you will need a two dimension (2-D) array to record the hours worked each day for an employee. The number of rows for the 2-D array should be the same as the arrays above since each row corresponds to an employee. The number of columns represents days of the week (7 last I looked) Functions Needed In this lab, you must read in the…arrow_forwardI need help with thisarrow_forwardQ1/ Write a script code to create two matrices, one with size (5x8) and the second with size (6x9), choose any numbers for both matrices.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY