Monday 14 February 2022

C Program To Convert Octal number To Decimal number

 OCTAL TO DECIMAL NUMBER CONVERTER PROGRAM

Code :

#include<stdio.h>

int obase( int i){
     int sum=1;
    if(i==0)
    {
        return 1;
    }
    for(int j=0; j<i; j++)
    {
        sum *= 8;    
    }
    return sum;
}

int main()
{
    int base=0, octn, temp = 0, i = 0, dec = 0;
           
           printf("==========================================\n");
   printf("\tOCTAL TO DECIMAL CONVERSION\n");
    printf("==========================================\n");

    printf("Enter Octal number: ");
    scanf("%d", &octn);
   
    //Logic of conversion
    while(octn!=0)
    {
        temp = octn%10;
        octn = octn/10;
        base = obase(i);       //Obtain base
        dec += temp*base;
        i++;
    }
   
    printf("\nEquivalent decimal number = %d\n", dec);
    printf("------------------------------------------\n");


    return 0;
}
Come again Learn again !

< iCode Buzz />



No comments:

Post a Comment