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
nadezda [96]
3 years ago
8

write a c++ program that reads from the user a positive integer (in a decimal representation), and prints its binary (base 2) re

presentation. Your program should interact with the user exactly as it shows in the following example: Enter decimal number: 76 The binary representation of 76 is 1001100
Computers and Technology
1 answer:
Vesna [10]3 years ago
5 0

Answer:

The program to this question can be described as follows:

Program:

#include <iostream> //defining header file

using namespace std;

int main() //defining main method

{

int x1,rem,i=1; //defining integer variable

long Num=0;// defining long variable

cout << "Input a decimal number: "; // print message

cin >> x1; //input value by user

while (x1!=0) //loop for calculate binary number

{

//calculating binary value    

rem= x1%2;

x1=x1/2;

Num =Num +rem*i;//holding calculate value

i=i*10;

}

cout <<Num;//print value

return 0;

}

Output:

Input a decimal number: 76

1001100

Explanation:

In the above code, four variable "x1, rem, i, and Num" is declared, in which three "x1, rem, and i" is an integer variable, and one "Num" is a long variable.

  • In the x1 variable, we take input by the user and use the while loop to calculate its binary number.
  • In the loop, first, we check x1 variable value is not equal to 0, inside we calculate it binary number that store in long "Num" variable, after calculating its binary number the print method "cout" is used to prints its value.  
You might be interested in
Which of the following is an example of physical noise?
solniwko [45]
What are the options

6 0
3 years ago
What is the best application to create a slide show presentation?
Lynna [10]

Answer:

Microsoft Windows File Manager

5 0
3 years ago
Read 2 more answers
Write an application of computer in robotics?​
MariettaO [177]

Answer:

In robotics, one use the computer has is to help program the robots.

4 0
3 years ago
Where did the Internet originate
natali 33 [55]
From scientists planing to share information across countries. Letters and the mail system took to long for certain situations. 
3 0
3 years ago
Read 2 more answers
What translates binary data into images on a monitor?
g100num [7]
A video card is what allows a computer to translate the binary data into images.
8 0
3 years ago
Other questions:
  • A food web is shown below. In this food web, energy is transferred directly from the to the
    11·1 answer
  • How long does it take to wire a house?
    14·2 answers
  • How were the pages made to create the Book of Kells? a. Scribes prepared the papers using a printing press. b. 185 calves were s
    9·1 answer
  • 1. Which sign-in method requires users to press Ctrl+Alt+Delete before signing in?
    5·1 answer
  • How to fix Please enable JS and disable any ad blocker
    13·2 answers
  • You are adding a new 500 GB hard drive to your computer. The hard drive must be formatted with a file system to organize files i
    8·1 answer
  • What steps might a company or organization need take in order to keep its digital data secure online?
    8·1 answer
  • PLEASE HELP ASAP (answer is needed in Java) 70 POINTS
    15·1 answer
  • Referat noaptea la școala cu sfârșit de groază​
    10·1 answer
  • I don't know if this is supposed to go here or art but i need help with photoshop, basically you can create whatever you want bu
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!