C program to convert Binary number to Octal number

Simple C program to convert Binary number to Octal number

Code:

#include<stdio.h>
#include<conio.h>
int main()
{
long int n,rem,base=1,dec=0;
long int i=0,j,k,rem2[10],dec2;
clrscr();
printf("Enter the Binary code: ");
scanf("%li",&n);
{
while (n>0)
{
rem=n%10;
dec=dec+base*rem;
n=n/10;
base=base*2;
}


}
{
printf("\nDecimal value is %li",dec);
dec2=dec;
while(dec2>0)
{
rem2[i]=dec2%8;
i++;
dec2=dec2/8;
}
printf("\nOctal value: ");
for(k=i-1;k>=0;k--)
printf("\%li ",rem2[k]);
}
getch();
}

Comments

Popular posts from this blog

C program to evaluate Prefix Expression using Stack data structure

Java Program to Implement sorting algorithm using TCP on Server application

C++ program to perform data transformation Min-max and Z score Normalization