c program to convert octal number into the Decimal number.

Spread the love

Example:

Octal  = 123
Decimal= 1×8²+2×8¹+3×8⁰ = 83

Program (Octal to Decimal Conversion):

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main ()
  4. {
  5.     int decimal=0, i=0, rem=0,n,n1;
  6.     printf(“Enter the octal number : “);
  7.     scanf(“%d”,&n);
  8.     n1=n;
  9.     while (n!=0)
  10.     {
  11.         rem = n%10;
  12.         n = n/10;
  13.         decimal = decimal + rem * pow(8,i);
  14.         i++;
  15.     }
  16.     printf(“%d in octal is equal to %d in decimal n,n1,decimal);
  17.     return 0;
  18. }

Output:

Similar Programs:

Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer and an Open Source enthusiast, Presently working as a Software Engineer. Apart from that, I love to explore new technologies and things.

You may also like...

1 Response

  1. Decimal to Binary, Octal and HEX converter

    Decimal to Binary, Octal and HEX converter

    #include
    #include
    #define MAX 79
    #define ESC 27
    void main()
    {
    char res,r;
    int i,k=0,y;
    long j=0,l=0,o=0;
    textcolor(15);
    for(i=0;i<5000;i++)
    cprintf(" ");
    while(1)
    {
    clrscr();
    printf("Enter Any Number To Be Converted : ");
    scanf("%ld",&j);
    l=j;
    o=l;
    k=0;
    if(j>2145555550)
    {
    textcolor(4);
    gotoxy(15,5);
    cprintf("The Number Is Greater Than Range");
    textcolor(15);
    getch();
    goto end;
    }
    else
    {
    gotoxy(1,6);
    printf("Binary Equivalent:-");
    y=MAX;
    while(j>0)
    {
    k=j%2;
    j=j/2;
    gotoxy(y,6);
    y–;
    printf("%d",k);
    }
    gotoxy(1,8);
    printf("Hexadecimal Equivalent:- ");
    y=MAX;
    while(l>0)
    {
    k=l%16;
    l=l/16;
    gotoxy(y,8);
    y–;
    if(k<=9)
    {
    printf("%d",k);
    }
    if(k==10)
    {
    printf("A");
    }
    if(k==11)
    {
    printf("B");
    }
    if(k==12)
    {
    printf("C");
    }
    if(k==13)
    {
    printf("D");
    }
    if(k==14)
    {
    printf("E");
    }
    if(k==15)
    {
    printf("F");
    }
    }
    gotoxy(1,10);
    printf("Octal Equivalent:- ");
    y=MAX;
    while(o>0)
    {
    k=o%8;
    o=o/8;
    gotoxy(y,10);
    y–;
    printf("%d",k);
    }
    }
    gotoxy(15,25);
    printf("Press Any Key To Continue , ESC To Exit");
    res=getch();
    if(res==ESC)
    {
    break;
    }
    }
    end:
    textcolor(7);
    for(i=0;i<5000;i++)
    cprintf(" ");
    clrscr();
    }

Leave a Reply