117 Views

C++ program to convert decimal to binary 1.without using recursion 2.with using recursion


Sahithi K 17th Sep, 2019
Answer (1)
Shubham Kumar Gupta 17th Sep, 2019

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.

Related Questions

Amity University-Noida B.Tech...
Apply
Among top 100 Universities Globally in the Times Higher Education (THE) Interdisciplinary Science Rankings 2026
Indus University M.Tech Admis...
Apply
Highest CTC 26 LPA | Top Recruiters: Accenture, TCS, Tech Mahindra, Capgemini, Microsoft
New Horizon College BBA Admis...
Apply
UG Admissions 2026 open| NAAC ‘A’ grade | Merit-based Scholarships available.
VIT Bhopal University | B.Arc...
Apply
Mark presence in the Modern Architectural field with Bachelor of Architecture | Highest CTC : 70 LPA | Accepts NATA Score
VIT Bhopal University | Integ...
Apply
Integrated M.Tech admissions open @ VIT Bhopal University | Highest CTC 70 LPA | Application Closing Soon | Apply now
MAHE, Manipal - B.Tech Admiss...
Apply
Final Application Deadline: 23rd March | NAAC A++ Accredited | Accorded institution of Eminence by Govt. of India | NIRF Rank #3
View All Application Forms

Download the Careers360 App on your Android phone

Regular exam updates, QnA, Predictors, College Applications & E-books now on your Mobile

150M+ Students
30,000+ Colleges
500+ Exams
1500+ E-books