adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C and C++ to Convert Octal to Decimal number Using recursive function

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 

Post a Comment

0 Comments