Binary to Decimal Conversion Program in C Programming
On this page (5sections)
About this program
This is an example program in c other programs. Read the concept first: If Else Statement in C, then study the code and output below.
Example Program For Binary to Decimal Conversion
/* Example Program For Binary to Decimal In C Programming Language
little drops @ thiyagaraaj.com
Coded By:THIYAGARAAJ MP \*/
// Header Files
#include<stdio.h>
#include<conio.h>
int to_decimal(int);
//Main Function
int main()
{
//Varibale Declaration
int n;
printf("Enter the Binary Number:");
scanf("%d",&n);
printf("Decimal Numebr : %d",to\_decimal(n));
// Wait For Output Screen
getch();
//Main Function return Statement
return 0;
}
// Function for Binary to Decimal
int to_decimal(int num)
{
int sum=0,i=0;
while(num!=0)
{
sum=sum+(num%10)\*pow(2,i++);
num/=10;
}
return sum;
}
Sample Output:
Enter the Binary Number:1010
Decimal Numebr : 10
Enter the Binary Number:1000
Decimal Numebr : 8
Related Pages
Learn the concept first, then study the code:
- C Programs — Browse all C Programs.
- If Else Statement in C — Tutorial — decision control for utility programs.
- Reverse Number Example Program In C Programming Language — More in c other programs.
- Example Program for Print 1 to N In C Programming — More in c other programs.
Frequently Asked Questions
What does this C program do?
It is a C example program that demonstrates Binary to Decimal Conversion, including the complete source code and the expected sample output.
How do I compile and run this C program?
Save the code in a `.c` file, compile it with `gcc filename.c -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses core C syntax, illustrating a common pattern in C programming.