0% found this document useful (0 votes)
53 views4 pages

Dcit 102 Assignment

This C++ program contains functions to convert a decimal number to binary, octal, and hexadecimal representations. The user inputs a decimal number, and the program outputs the decimal number along with its binary, octal, and hexadecimal equivalents. It uses modulo and division operations within while loops to extract the digits of each converted number and store them in arrays, then outputs the arrays in reverse order to display the converted numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views4 pages

Dcit 102 Assignment

This C++ program contains functions to convert a decimal number to binary, octal, and hexadecimal representations. The user inputs a decimal number, and the program outputs the decimal number along with its binary, octal, and hexadecimal equivalents. It uses modulo and division operations within while loops to extract the digits of each converted number and store them in arrays, then outputs the arrays in reverse order to display the converted numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

QUESTION 1

CONVERTING DECIMAL TO BINARY , HEXADECIMAL AND OCTAL


#include <iostream>

using namespace std;

void Decimal_To_Binary(int number);

void Decimal_To_Octal(int number);

void Decimal_To_Hex(int number);

int main() {

int number;

cin >> number;

if(number < 0)

cout << "Please, enter positive number!";

else

cout << "DEC: " << number;

cout << "\nBIN: ";

Decimal_To_Binary(number);

cout << "\nOCT: ";

Decimal_To_Octal(number);

cout << "\nHEX: ";

Decimal_To_Hex(number);

}
}

void Decimal_To_Binary(int number)

int binaryNum[1000];

int i=0;

while (number > 0)

binaryNum[i] = number % 2;

number = number / 2;

i++;

for (int j = i - 1; j >= 0; j--)

cout << binaryNum[j];

void Decimal_To_Octal(int number)

int octalNum[100];

int i=0;

while (number != 0)

octalNum[i] = number % 8;

number = number / 8;

i++;

}
for (int j = i - 1; j >= 0; j--)

cout << octalNum[j];

void Decimal_To_Hex(int number)

char hexaDeciNum[100];

int i=0;

while(number != 0)

int temp=0;

temp = number % 16;

if(temp < 10)

hexaDeciNum[i] = temp + 48;

i++;

else

hexaDeciNum[i] = temp + 55;

i++;

number = number/16;

}
for(int j=i-1; j >= 0; j--)

cout << hexaDeciNum[j];

QUESTION 2

You might also like