Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Mathematics ProgramRSS Feeds

Program to convert a decimal number into binary, octal and pental code

Posted By: Easy Tutor     Category: C++ Programming     Views: 17873

A C++ program to convert a decimal number into binary, octal and pental code ( using arrays and functions with return type).

Code for Program to convert a decimal number into binary, octal and pental code in C++ Programming

 #include<iostream.h>
 #include<conio.h>
 #include<stdio.h>


 long binary_code(int);
 double pental_code(int);
 double octal_code(int);

 main()
    {

       clrscr();

       int number;

       cout<<"\n ********** Decimal Number *********"<<endl;
       cout<<"\n For binary numbers ,enter from( 0 ---> 1023 ) "<<endl;

       cout<<"\n\n Enter the Decimal number = ";
       cin>>number;

       cout<<"\n ********** Binary Number **********"<<endl;
       cout<<"\t Binary Number = "<<binary_code(number)<<endl;

       cout<<"\n *********** Pental Code ***********"<<endl;
       cout<<"\t Pental Code = "<<pental_code(number)<<endl;

       cout<<"\n *********** Octal Code ************"<<endl;
       cout<<"\t Octal Code = "<<octal_code(number)<<endl;

       getch();
       return 0;
    }

 /*************************************************************************//*************************************************************************///------------------------  Function Definitions  -----------------------///*************************************************************************//*************************************************************************//*************************************************************************///---------------------------  binary_code(int)  ------------------------///*************************************************************************/long binary_code(int number)
    {
       int count=0;
       int resulting_array[25];
       int remainder;
       int qutiont;
       int size=0;

       long binary_number=0;
       long sum=0;
       longbase=1;

       while(number>0)
      {
         qutiont=number/2;
         remainder=number%2;
         number=qutiont;
         resulting_array[count]=remainder;

         size++;
         count++;
      }

       for(int j=0;j<size;j++)
      {
         sum=resulting_array[j]*base;
         base=base*10;
         binary_number+=sum;
      }

       return binary_number;
    }

 /*************************************************************************///---------------------------  pental_code(int)  ------------------------///*************************************************************************/double pental_code(int number)
    {
       int count=0;
       int resulting_array[25];
       int remainder;
       int qutiont;
       int size=0;

       double pental_number=0;
       double sum=0;
       doublebase=1;

       while(number>0)
      {
          qutiont=number/5;
          remainder=number%5;
          number=qutiont;
          resulting_array[count]=remainder;

          size++;
          count++;
      }

       for(int j=0;j<size;j++)
      {
         sum=resulting_array[j]*base;
         base=base*10;
         pental_number+=sum;
      }
       return pental_number;
    }

 /*************************************************************************///----------------------------  octal_code(int)  ------------------------///*************************************************************************/double octal_code(int number)
    {
       int count=0;
       int resulting_array[25];
       int remainder;
       int qutiont;
       int size=0;

       double octal_number=0;
       double sum=0;
       doublebase=1;

       while(number>0)
      {
          qutiont=number/8;
          remainder=number%8;
          number=qutiont;
          resulting_array[count]=remainder;

          count++;
          size++;
      }

       for(int j=0;j<size;j++)
      {
         sum=resulting_array[j]*base;
         base=base*10;
         octal_number+=sum;
      }
       return octal_number;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program to convert a decimal number into binary, octal and pental code is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Miss Eyda from Malaysia Comment on: Sep 03
Hello, I am ida, please help me to built one program using C++, the program is to enable process of converting number to binary or octal number format.Program will start by requesting user to key-in any number.Then, the user can choose whether want to convert the number to binary number format or octal number format.This program is should generate the code based on the selection user.The output will be display to user based on the selection before.All the process in converting number to binary or octal format number will be implement using stack with linked list.

View All Comments