Tuesday 31 May 2016

Write a Program that inputs a decimal number and convert it to binary digits.

#include<iostream.h>
#include<conio.h>
void binary(unsigned long int decimal)
{
      int remainder; 
      if(decimal <= 1)
      {
       cout<<decimal;
       return; 
      }
      remainder = decimal % 2; 
      binary(decimal >>1);
      cout<< reminder; 
}
void main()
{
      unsigned long int num; 
      clrscr(); 
      cout<<"Enter decimal"; 
      cin>> num; 
      cout<<endl<<"Binary of "<<num<<" is ";
      binary(num);
      getch();
}

Share:

0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

About Me

My photo
A group of two, with a little hope of helping beginners to learn how to code :)
Powered by Blogger.

Comments

Facebook

Ad Home

Follow Us

Random Posts

Sponsor

Recent Posts

Header Ads

Popular Posts

Copyright © Functions in C++ | Powered by Blogger

Design by ThemePacific | Blogger Theme by NewBloggerThemes.com | Distributed By Blogger Templates20