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
This is used to copy information from cell to cell in the spread sheet
Kryger [21]

Answer:

D. Fill handle

Explanation:

Required

Which can be used to copy from cell to cell

(a); Means the current cell being selected in the spreadsheet program

(b): Used to fit all columns in the spreadsheet program. Usually, the columns are fitted based on their width.

(c): The vertical and horizontal lines that separate cells.

(d): This is used to copy from one cell to another, especially adjacent cells.

5 0
3 years ago
What is database? Please answer ASAP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ON Microsoft power
ad-work [718]
A database is where data is stored. Also known as a structured set of data held in a computer.
4 0
3 years ago
Read 2 more answers
As an IT specialist you are asked to troubleshoot a problem with two
Kamila [148]

Answer:

B

Explanation:

5 0
3 years ago
Read 2 more answers
What is an audit trial
Nastasia [14]

Hi there!

A audit trial is a report of changes that have been obtained to a file or some kind of database.

Hope this helped!~

7 0
3 years ago
What is the value of 25 x 103 = ________?
ira [324]

Answer:

2575

heres coorect

6 0
3 years ago
Read 2 more answers
Other questions:
  • What is the difference between the new and open commands on the file menu
    12·1 answer
  • What is the area of a triangle whose base is 14 m and whose height is 22 m?
    7·1 answer
  • What is an advantage of using a meta-search engine?
    14·1 answer
  • A machine on a 10 Mbps network is regulated by a token bucket algorithm with a fill rate of 3 Mbps. The bucket is initially fill
    12·1 answer
  • How can I record Tv shows on the Android OTT TV BOX either on the Box or on Kodiak without buying a Tv Tuner?
    12·2 answers
  • Last bittttt of points
    8·1 answer
  • O O O O O O O
    9·1 answer
  • What would be the greatest tool for emphasis? (video class)
    9·1 answer
  • The Internet:
    12·1 answer
  • Consider an individual who wishes to ensure that their information remains secure and confidential, possibly to secure their per
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!