#include <stdio.h>
#include<conio.h>
void main()
{
clrscr();
long int binary_num, octal_num=0;
int i=1, rem;
printf("\n Enter the binary number:");
scanf("%ld",&binary_num);
while(binary_num!=0)
{
rem = binary_num % 10;
octal_num = octal_num + rem * i;
i = i * 2;
binary_num = binary_num / 10;
}
printf("\n Equivalent Octal value = %ld", octal_num);
getch();
}
Run1:
Run2:
Previous Next
#include<conio.h>
void main()
{
clrscr();
long int binary_num, octal_num=0;
int i=1, rem;
printf("\n Enter the binary number:");
scanf("%ld",&binary_num);
while(binary_num!=0)
{
rem = binary_num % 10;
octal_num = octal_num + rem * i;
i = i * 2;
binary_num = binary_num / 10;
}
printf("\n Equivalent Octal value = %ld", octal_num);
getch();
}
Run1:
Run2:
Previous Next
No comments:
Post a Comment