1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lina2011 [118]
2 years ago
11

In C coding, write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the int

eger in binary. For an integer x, the algorithm is:
As long as x is greater than 0
Output x % 2 (remainder is either 0 or 1)
x = x / 2
Note: The above algorithm outputs the 0's and 1's in reverse order.

Ex: If the input is:

6
the output is:

011
6 in binary is 110; the algorithm outputs the bits in reverse.

#include

int main(void) {

/* Type your code here. */

return 0;
}
Computers and Technology
1 answer:
lbvjy [14]2 years ago
5 0

The program illustrates the use of modulo operators

The modulo operator is used to return the remainder of a division

Take for instance:

5 % 3 is 2, because the result of 5 divided by 3 is 1 remainder 2

So, the complete program, where comments are used to explain each line is as follows:

#include<iostream>

#include<string>

using namespace std;

int main(void) {

//This declares num as integer

int num;

//This declares binary as string

string binary;

//This gets input for num

cin>>num;

//The following iteration is repeated while num is greater than 0

while(num>0){

   //This gets the remainder of num divided by 2

   binary+=to_string(num%2);

   //This divides num by 2

   num/=2;

}

//The reverses the binary string

binary = string(binary.rbegin(),binary.rend());

//This prints the binary string

cout<<binary;

return 0;

}

At the end of the program, the binary string is printed

See attachment for sample run

Read more about modulo operators at:

brainly.com/question/17760417

You might be interested in
What number system is the basis for all of the powerful computers and electronic devices in the world?
labwork [276]

Answer:

Binary

Explanation:

3 0
3 years ago
A vast global network that is made up of many smaller interconnected networks is known as:
Galina-37 [17]

The answer is The Internet.   It is a vast global network that is made up of many smaller interconnected networks. It connects to millions of computer units world wide, in which any computer can communicate with any other computer as long as they are both connected to the Internet. It also made access to information and communication easier.

6 0
4 years ago
Read 2 more answers
Have you searched Buzz Ch.at on playstore​
deff fn [24]

Answer:

Reorder terms.

y=52x−1

Cancel the common factor of 22.Factor 22 out of −2-2.

y−4=5x2+52⋅(2(−1))y-4=5x2+52⋅(2(-1))

Cancel the common factor.

y−4=5x2+52⋅(2⋅−1)y-4=5x2+52⋅(2⋅-1)

Rewrite the expression.

y−4=5x2+5⋅−1y-4=5x2+5⋅-1

Multiply 55 by −1-1.

y−4=5x2−5

3 0
3 years ago
Copy the skeleton of code below into your answer. Then in the space indicated, add your own code to prompt the user for two numb
ahrayia [7]

Answer:

import java.util.*;

public class Main

{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

   

 System.out.print("Enter the first: ");

 int first = input.nextInt();

 System.out.print("Enter the second: ");

 int second = input.nextInt();

 input.nextLine();

 System.out.print("Enter your name: ");

 String name = input.nextLine();

 

 int difference = Math.abs(second - first);

 

 System.out.println(name + ", the difference is " + difference);

}

}

Explanation:

*The code is in Java.

Create a Scanner object to get input from the user

Ask the user to enter the first, second, and name

Calculate the difference, subtract the second from the first and then get the absolute value of the result by using Math.abs() method

Print the name and the difference as in required format

7 0
3 years ago
What are the core components of a computer system? CPU, RAM, ROM, I/O ports, keyboard CPU, RAM, ROM, I/O ports, system bus CPU,
zimovet [89]
CPU, RAM, ROM, system bus, I/O ports
8 0
4 years ago
Read 2 more answers
Other questions:
  • 1. Which of the following is required to create a computer simulation?
    11·1 answer
  • What two names are used to describe the configuration in which internal and ​external dns queries are handled by different dns s
    13·1 answer
  • In real-world environments, risks and their direct consequences will most likely span across several domains. However, in the la
    12·1 answer
  • Does anyone know to get Google updated if it failed to update?
    12·1 answer
  • Abby wants to simply share a snapshot of her calendar with another user. Which option should she choose to achieve
    15·1 answer
  • How long does it take to go 80 miles if you are going 80 mph?
    8·2 answers
  • Lucy wants to add some notes in her research paper that provide additional information to the reader. She also wants to display
    14·1 answer
  • Give a regular expression for binary numbers. They can be integers or binary fractions. A leading - sign is always allowed. Lead
    15·1 answer
  • Freee poiiiiintttttssss​
    14·2 answers
  • What is the reason for taking care of design a good computer human interface ​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!