2020-05-29 23:23:24 +03:00
|
|
|
// Program to convert decimal number to octal (Using Reccursion)
|
|
|
|
// This program only works for integer decimals
|
|
|
|
// Created by Aromal Anil
|
2019-10-27 12:24:24 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
int decimal_to_octal(int decimal)
|
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
if ((decimal < 8) && (decimal > 0))
|
|
|
|
{
|
|
|
|
return decimal;
|
|
|
|
}
|
|
|
|
else if (decimal == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ((decimal_to_octal(decimal / 8) * 10) + decimal % 8);
|
|
|
|
}
|
2019-10-27 12:24:24 +03:00
|
|
|
}
|
2020-04-08 16:41:12 +03:00
|
|
|
int main()
|
2019-10-27 12:24:24 +03:00
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
int octalNumber, decimalNumber;
|
|
|
|
printf("\nEnter your decimal number : ");
|
|
|
|
scanf("%d", &decimalNumber);
|
|
|
|
octalNumber = decimal_to_octal(decimalNumber);
|
|
|
|
printf("\nThe octal of %d is : %d", decimalNumber, octalNumber);
|
|
|
|
return 0;
|
2019-10-27 12:24:24 +03:00
|
|
|
}
|