mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
Created algorithm to convert binary to octal. (#478)
* Created algorithm to convert binary to octal. This contatin algorithm to convert binary to octal using recursion * Rename decimal_to_octal_recursion to decimal_to_octal_recursion.c
This commit is contained in:
commit
8a77fb3c74
28
conversions/decimal_to_octal_recursion.c
Normal file
28
conversions/decimal_to_octal_recursion.c
Normal file
@ -0,0 +1,28 @@
|
||||
//Program to convert decimal number to octal (Using Reccursion)
|
||||
//This program only works for integer decimals
|
||||
//Created by Aromal Anil
|
||||
|
||||
#include <stdio.h>
|
||||
int decimal_to_octal(int decimal)
|
||||
{
|
||||
if( (decimal<8) && (decimal>0) )
|
||||
{
|
||||
return decimal;
|
||||
}
|
||||
else if(decimal==0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( (decimal_to_octal(decimal/8)*10) + decimal%8 );
|
||||
}
|
||||
}
|
||||
void main()
|
||||
{
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user