📅  最后修改于: 2022-03-11 14:44:48.755000             🧑  作者: Mango
// program to convert decimal to OCTAL
#include
using namespace std;
#define size 50
int st[size];
int top = -1;
void push(int);
int pop();
int isempty();
int isfull();
int main()
{
int num, n, r;
cout << "\nenter decimal number: ";
cin >> num;
n = num;
while (n >= 1)
{
r = n % 8;
push(r);
n = n / 8;
}
cout << "DECIMAL :: " << num << endl;
cout << "OCTAL :: ";
while (!isempty())
cout << pop();
return 0;
}
int isempty()
{
if (top == -1)
return 1;
return 0;
}
int isfull()
{
if (top == size - 1)
return 1;
return 0;
}
void push(int r)
{
if (isfull())
cout << ("\nSTACK OVERFLOW\n");
else
st[++top] = r;
}
int pop()
{
if (isempty())
{
return 0;
cout << ("\nSTACK UNDERFLOW\n");
}
else
return st[top--];
}