C Program to Convert Binary to Octal

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Program for Binary to decimal and decimal to octal
#include<stdio.h>
#include<conio.h>
#define clrscr() system("cls")
int main()
{
    int n,dn=0,r,b=1,binary,i=0,ar[50];
     clrscr();
     printf("Enter a binary number( only 0 and 1 format)");
     scanf("%d",&n);
     binary=n;
     while(n!=0)
     {
          r=n%10;
          dn=dn+r*b;
          b=b*2;
          n=n/10;
     }
     printf("\n Binary No is : %d",binary);
     //printf("\n Decimal No is : %d",dn);
     while(dn!=0)
     {
          r=dn%8;
          ar[i]=r;
          i++;
          dn=dn/8;
     }
     i--;
     printf("\n Octal No is :");
     while(i>=0)
     {
          printf("%d",ar[i]);
          i--;
     }
}

 

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *