Program in C and C++ to Convert Octal to Decimal number Using recursive function
C Program
#include<stdio.h> int octToDec(int oct){ static int base = 1; if(oct == 0) return 0; return ((oct % 10 ) * ((base *= 8 ) / 8 ) + octToDec(oct / 10)); } int main(){ int n; printf("Enter octal number :- "); scanf("%d",&n); printf("Decimal : %d",octToDec(n)); return 0; }
C++ Program
#include<iostream> int octToDec(int oct){ static int base = 1; if(oct == 0) return 0; return ((oct % 10 ) * ((base *= 8 ) / 8 ) + octToDec(oct / 10)); } int main(){ int n; std::cout<<"Enter octal number :- "; std::cin>>n; std::cout<<"Decimal : "<<octToDec(n); return 0; }
Output :-
Related Programs
- Program in C & C++ to print the binary equivalent 1 to nth number.
- Program in C++ to Convert Binary to Decimal number Using Function
- Program in C to convert decimal into octal number.
- Program in C++ to Convert Hexadecimal to Decimal number Using Function
- Program in C++ to Convert Decimal to Hexadecimal number Using Function
- Program in C to Convert Decimal to Binary number.
- Program in C to print the binary equivalent 1 to nth number.
- Program in C and C++ to Convert Decimal to Binary number Using recursive function
- Program in C and C++ to Convert Binary to Decimal number Using recursive function
- Program in C and C++ to Convert Decimal to Octal number Using recursive function
0 Comments