We have been working very hard since 2009 to facilitate in learning Read More. We can't keep up without your support. Donate.

www.vustudents.ning.com

 www.bit.ly/vucodes + Link For Assignments, GDBs & Online Quizzes Solution www.bit.ly/papersvu + Link For Past Papers, Solved MCQs, Short Notes & More

Decimal to Binary conversion in c++ by using the Recursion

Decimal to Binary conversion in c++ by using the Recursion

See the code given below i sure you will found some errors while compiling this code. So, please don't forget to put less than and greater than expression after cout and cin. these expression has been removed due to the ning.api does not support to these expression so put them after cin and cout.
This code will convert to a Decimal number into Binary code.
we will learn in this code:

1. Functions
2. Recursion
3. Use of Modulus operator

I hope you can understand this code easily. if you have any problem then you may ask.

#include<iostream>
using namespace std;
void convert(int);
main(){
int number;

cout "Please enter a positive integer: ";
cin >> number;
if (number < 0)
cout "That is not a positive integer.\n";
else {
cout endl number " converted to binary is: ";
convert(number);
cout endl;
}
coutendl;
system("pause");
return 0;
}
void convert(int number) {
int remainder;

if(number <= 1) {
cout number;
return;
}

remainder = number%2;
convert(number >> 1);
cout remainder;
}

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

Views: 203

Attachments:

Replies to This Discussion

good job

thanku

agr vaule -ve ho to kia us ko binary mn convert ni kia ja skta??? is mn +ve hi q?

kr sakty hen convert

Latest Activity

Saba liked ★彡[ꜱʜʏɴᴀ]彡★'s discussion usi k naam sey jeena, usi sey merna hai
48 minutes ago
Saba liked Mani Siddiqui Ex's discussion General Knowledge question !!!
48 minutes ago
Honey Bun liked Mani Siddiqui Ex's discussion General Knowledge question !!!
49 minutes ago
1 hour ago
1 hour ago
1 hour ago
Blessing posted a status
"Wo log bht saaf dil hote hn jin k choti choti bat pr ansu nikl ate hn."
3 hours ago
muhammad saim and Rabia joined Virtual University of Pakistan
3 hours ago
★彡[ꜱʜʏɴᴀ]彡★ liked Mani Siddiqui Ex's discussion General Knowledge question !!!
4 hours ago
4 hours ago
5 hours ago
5 hours ago