Binary to Decimal Conversion Program In C Programming
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
Read More Articles
- Use of getch(),getche() and getchar() in C
- Switch Case Statement Example Program In C Programming Language
- C Character Set
- Convert a Floating-point value to an Integer in C
- Data Input and Output gets and puts Example Program In C
- Special Operators In C
- Pointer Representation and Pointer Example Programs
- C Data Input and Data Output
- Simple While Loop Example Program In C Programming Language
- Data Output printf and putchar Example Program In C
- C Introduction
- C Operators
- Storage Classes In C
- C Pointers
- C Identifiers
- File Management
- Loop Control Statements
- Hello World - Simple C Program
- C Array
- Single Character Output Function : putchar()
- C Reserve Words
- C Specific Properties and Implementation
- If else Statement Example Program In C Programming Language
- If Statement Example Program In C Programming Language
- Confusing Array in C ( Array Representation and Initialization )