answersLogoWhite

0

include <iostream>

using namespace std;

int main() {

int n; // number to convert to binary

while (cin >> n) {

if (n > 0) {

cout << n << " (decimal) = ";

while (n > 0) {

cout << n%2;

n = n/2;

}

cout << " (binary) in reverse order" << endl;

} else {

cout << "Please enter a number greater than zero." << endl;

}

}

return 0;

}//end main

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Write a program that converts a decimal number to nearest integer?

prompt x floor(x + .5) -&gt; x disp x


How do you write 5 as an integer?

5 is an integer; it is a whole number without a decimal or fraction.


How do you write a program to find number of zeros for the given number in c program?

Assuming the number is represented by a decimal integer, initialise a counter to zero, then repeatedly divide the number by 10 and until the number is zero. After each division, examine the remainder. Each time the remainder is zero, increment the counter. If the number is represented by a decimal float, repeatedly multiply by 10 until the value is an integer, then perform the previous algorithm.


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


How do you write a Java program to convert a decimal number to an octal number?

public class Dataconversion { public static void main(String[] args) { System.out.println("Data types conversion example!"); int in = 44; System.out.println("Integer: " + in); //integer to binary String by = Integer.toBinaryString(in); System.out.println("Byte: " + by); //integer to hexadecimal String hex = Integer.toHexString(in); System.out.println("Hexa decimal: " + hex); //integer to octal String oct = Integer.toOctalString(in); System.out.println("Octal: " + oct); } }


How do you write the value of a decimal?

You first write the integer part, then write the decimal point and then the fractional part in decimal form.


How do you Write a C program to reverse an Integer number.?

Reference:cprogramming-bd.com/c_page2.aspx# reverse number


How do you write -45 as a decimal?

To write -45 as a decimal, you simply write &quot;-45.0&quot; or &quot;-45.00&quot; to indicate the number includes a whole number and decimal point. The decimal form of -45 represents the same value as the integer -45, but with a decimal point to show its position on the number line. The negative sign indicates that the number is less than zero.


How do you write 50000 as integer?

To write 50,000 as an integer, you simply write the number without any decimal or fractional parts. In this case, 50,000 is already an integer because it is a whole number with no decimal or fractional component. Therefore, you can express 50,000 as an integer by writing it as &quot;50,000.&quot;


Write a C program to convert hexadecimal number into decimal number?

pongada punda vayanungala ..................


How do you write an integer?

The reason you're having so much difficulty writing it is that there's no such thing as an "interger". An "integer" is a whole number. Any time you write a number that doesn't have any fraction or decimal in it, you have written an integer.


Write a program to subtract integer y from integer x?

x -=y;