answersLogoWhite

0

#include<iostream>

#include<iomanip>

#include<string>

std::string dec_to_bin(unsigned dec)

{

std::string result = "";

char c = (dec & 0x1) + '0'; // 'push' char onto call stack

if( dec >>= 1)

result += dec_to_bin(dec); // recurse

return result + c; // 'pop' char from call stack

}

int main()

{

// Print the first 256 binary numbers.

for (unsigned num=0; num<256; ++num)

{

std::cout.fill(' ');

std::cout << std::setw(10) << num << " decimal is ";

std::cout.fill('0');

std::cout << std::setw(32) << dec_to_bin(num) << " binary\n";

}

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

Differences between declaring a method and calling a method?

Declaring a method is when you code for what the method will perform. When you call a method, you are using the method you have written in another part of the program, (or inside the method if it is recursive).


Jntu 2-2 oops through java answers?

write a java program to find factorial using recursive and non recursive


Write a c program to find GCD of two given integers by using both recursive n non recursive functions?

i love u darling


Biggest of three nos using recursive method?

biggest3 (a,b,c) = biggest2 (a, biggest2 (b,c))


C program to implement tower of hanoi using array implementation of stack abstract datatype?

stack abstract datatype


Can you use stack in microprocessor for storage of data?

Yes, but not for long term storage, only while a program is executing using its stack.


What does recursive mean?

Recursive refers to using a rule or procedure that can be applied repeatedly.


Write a program to find gcd using recursive method in java?

for two positive integers: public static int gcd(int i1, int i2) { // using Euclid's algorithm int a=i1, b=i2, temp; while (b!=0) { temp=b; b=a%temp; a=temp; } return a; }


Write a program to convert stack into queue using c language?

In order to write a program to convert stack into queue using c language you must be able to identify the proper program. Having a special certification in programing will be beneficial as well to make sure you recognize the proper queues for the programs.


Implementation of stack using recursion?

public void reverse(Stack st) { int m = (int)st.Pop(); if (st.Count != 1) reverse(st); Push(st , m); } public void Push(Stack st , int a) { int m = (int)st.Pop(); if (st.Count != 0) Push(st , a); else st.Push(a); st.Push(m); }


What is flowchart of stack using array in c prog?

Two little problems: 1. stack doesn't have a flow-chart 2. there are no flow-charts in a C program


The efficiency of using recursive function rather than using ordinary function?

For some algorithms recursive functions are faster, and there are some problems that can only be solved through recursive means as iterative approaches are computationally infeasible.