The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int octal[100], num, i=0, j;
cout<<"Enter a decimal number: ";
cin>>num;
while (num>0)
{
octal[i]=num%8;
num=num/8;
i++;
}
cout<<"The octal equivalent is ";
for (j=i-1; j>=0; j--)
cout<<octal[j];
getch();
}
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
int main()
{
int num, i=0, j=0, x;
cout<<"Enter a decimal number: ";
cin>>num;
x=num;
while (x>0)
{
x=x/8;
j++;
}
int octal[j];
while (num>0)
{
octal[i]=num%8;
num=num/8;
i++;
}
cout<<"The octal equivalent is ";
for (j=i-1; j>=0; j--)
cout<<octal[j];
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP