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--;
}
}
Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google

