OCTAL TO DECIMAL CONVERSION

Consider the following I/O samples.




SAMPLE INPUT : 32

SAMPLE OUTPUT:  26




C PROGRAM:

#include <stdio.h>
int main()
{
    long int n, base=1, rem, ans=0;
    scanf("%ld",&n);
    while(n)
    {
        rem=n%10;
        ans=ans+rem*base;
        base=base*8;
        n=n/10;
    }
    printf("%ld",ans);
    return 0;
}

 


OUTPUT:

 



  
The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 
If you have any feedback about this article and want to improve this, please comment in the comment section.

 

Comments

Popular posts from this blog

INVERTED PYRAMID STAR PATTERN

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

Design a way to sort the list of positive integers in the descending order according to frequency of elements. The elements with integers with higher frequency come before with lower frequency elements with same frequency come in the same order as they appear the values.