You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
programming-examples/c/Basic/C Program to Convert Binary...

20 lines
504 B
C

/*
* C Program to Convert Binary to Octal
*/
#include <stdio.h>
int main()
{
long int binarynum, octalnum = 0, j = 1, remainder;
printf("Enter the value for binary number: ");
scanf("%ld", &binarynum);
while (binarynum != 0)
{
remainder = binarynum % 10;
octalnum = octalnum + remainder * j;
j = j * 2;
binarynum = binarynum / 10;
}
printf("Equivalent octal value: %lo", octalnum);
return 0;
}