C++ Program to Convert Decimal to Octal Number, Exercises of Introduction to Computers

covert decimal to octal exercise

Typology: Exercises

2017/2018

Uploaded on 12/11/2018

tewahido
tewahido 🇪🇹

2 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
// C++ program to convert a decimal
// number to octal number
#include <iostream>
using namespace std;
// function to convert decimal to octal
void decToOctal( int n)
{
// array to store octal number
int octalNum[100];
// counter for octal number array
int i = 0;
while (n != 0) {
// storing remainder in octal arr
octalNum[i] = n % 8;
n = n / 8;
i++;
}
// printing octal number array in rev
for ( int j = i - 1; j >= 0; j--)
pf2

Partial preview of the text

Download C++ Program to Convert Decimal to Octal Number and more Exercises Introduction to Computers in PDF only on Docsity!

// C++ program to convert a decimal // number to octal number #include using namespace std; // function to convert decimal to octal void decToOctal( int n) { // array to store octal number int octalNum[100]; // counter for octal number array int i = 0; while (n != 0) { // storing remainder in octal arr octalNum[i] = n % 8; n = n / 8; i++; } // printing octal number array in rev for ( int j = i - 1; j >= 0; j--)

cout << octalNum[j]; } // Driver program to test above function int main() { int n = 33; decToOctal(n); return 0; }