Question #16510

Problem 2:

Define your own function named TenToBinary, which will convert

a base-10 integer to a base-2 integer. The following steps are

required to be implemented in your program: (1) In your main

function, need to read an arbitrary input integer (nonnegative)

from the keyboard; (2) pass the input integer to your function (3)

convert the input integer which is based-10 to base-2; and (4)

print the binary value (base-2) in your own function. An example

is given as follows, which should be the format of your program

output on the console window (screen) after the execution.

we have to write this in c programming.

Define your own function named TenToBinary, which will convert

a base-10 integer to a base-2 integer. The following steps are

required to be implemented in your program: (1) In your main

function, need to read an arbitrary input integer (nonnegative)

from the keyboard; (2) pass the input integer to your function (3)

convert the input integer which is based-10 to base-2; and (4)

print the binary value (base-2) in your own function. An example

is given as follows, which should be the format of your program

output on the console window (screen) after the execution.

we have to write this in c programming.

Expert's answer

#include <iostream>

using namespace std;

void show_binary(unsigned int u)

{

while(u > 1)

{

if((u % 2) == 0)

{

std::cout << "0";

}

else

{

std::cout << "1";

}

u = u >> 1;

}

std::cout << "1" << std::endl;

}

int main(){

int number = 142;

show_binary(number);

system("PAUSE");

}

using namespace std;

void show_binary(unsigned int u)

{

while(u > 1)

{

if((u % 2) == 0)

{

std::cout << "0";

}

else

{

std::cout << "1";

}

u = u >> 1;

}

std::cout << "1" << std::endl;

}

int main(){

int number = 142;

show_binary(number);

system("PAUSE");

}

Learn more about our help with Assignments: C++

## Comments

## Leave a comment