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

MAHE Manipal M.Tech 2025
Apply
NAAC A++ Accredited | Accorded institution of Eminence by Govt. of India | NIRF Rank #4
University of Southampton Del...
Apply
MSc Finance and MSc International Management Admissions 2025 Now Open | Ranked Among the Top 100 Universities in the World by QS World University R...
Amity University, Noida Law A...
Apply
700+ Campus placements at top national and global law firms, corporates, and judiciaries
Chandigarh University Admissi...
Apply
Ranked #1 Among all Private Indian Universities in QS Asia Rankings 2025 | Scholarships worth 210 CR
Amrita Vishwa Vidyapeetham | ...
Apply
Recognized as Institute of Eminence by Govt. of India | NAAC ‘A++’ Grade | Upto 75% Scholarships
UPES B.Tech Admissions 2025
Apply
Ranked #42 among Engineering colleges in India by NIRF | Highest CTC 50 LPA , 100% Placements
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