C++ program to convert decimal to binary 1.without using recursion 2.with using recursion
Hello Sahithi, Greetings!
Required program without recursion:
- #include <iostream>
- using namespace std;
- int main()
- {
- int a[10], n, i;
- cout<<"Enter the number to convert: ";
- cin>>n;
- for(i=0; n>0; i++)
- {
- a[i]=n%2;
- n= n/2;
- }
- cout<<"Binary of the given number= ";
- for(i=i-1 ;i>=0 ;i--)
- {
- cout<<a[i];
- }
- }
Thank you, hope this helps.