C Program convert octal to binary number
Here, you will find the solution on how to convert the octal number to binary number in the c programming language. Following is the solution to the problem:
Code:
#include <math.h>
#include <stdio.h>
int main() {
int octal,original;
printf("Enter an octal number: ");
scanf("%d", &octal);
original=octal;
int deci = 0, i = 0;
long long bini = 0;
// convert octal to decimal
while (octal != 0) {
deci += (octal % 10) * pow(8, i);
++i;
octal /= 10;
}
int a = 1;
// convert decimal to binary
while (deci != 0) {
bini += (deci % 2) * a;
deci /= 2;
a*= 10;
}
printf("%d in octal = %lld in binary", original, bini);
return 0;
}
Output:
Enter an octal number: 25
25 in octal = 10101 in binary
Comments
Post a Comment