Binary to Decimal Conversion Program in C Programming
On this page (4sections)
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.