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
A hacker has successfully infected an internet-facing server which he will then use to send junk mail, take part in coordinated
julia-pushkina [17]
Botnet Trojan. Hopefully that’s helpful :)
5 0
3 years ago
Why is the radial gradient type a good choice for the grapes?
Grace [21]
<span>when you use the radial gradient fill it gives it a look like a shine on them. </span>
3 0
3 years ago
Read 2 more answers
Which part of a computer is responsible for executing the software programs?
mamaluj [8]

Answer:

c. CPU

Explanation:

7 0
3 years ago
Brake fluid is made up of a chemical that
Sidana [21]

Answer:

Most brake fluids used today are glycol-ether based, but mineral oil (Citroën/Rolls-Royce liquide hydraulique minéral (LHM)) and silicone-based (DOT 5) fluids are also available.

Explanation:

4 0
3 years ago
.حدد/ي الكيانات في النظام
olasank [31]

Answer:

what

Explanation:

6 0
2 years ago
Read 2 more answers
Other questions:
  • Write an algorithm whether the given number is positive negative or zero​
    5·1 answer
  • In an ha configuration, which two failure detection methods rely on icmp ping? (choose two.)
    12·1 answer
  • How do you change the slide layout?
    6·2 answers
  • Samantha wants to create a network group that allows open sharing of data without restrictions. What type of network should she
    9·1 answer
  • Users report that the network access is slow. After questioning the employees, the network administrator learned that one employ
    7·1 answer
  • A key physical design element is the ____, which describes how users interact with a computer system
    11·1 answer
  • Artificial intelligence seeks ways to improve a computer's capabilities in ____ and reasoning tasks. intellectual computational
    13·1 answer
  • A(n) ____ string contacts the data source and establishes a connection with the database using the Data Source Configuration Wiz
    5·1 answer
  • In a swap you need a variable so that one of the values is not lost ? Need help
    7·2 answers
  • Which background-repeat value represents this div?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!