C C++ program to convert binary to decimal

C C++ program to convert binary to decimal

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C और C++ दोनों भाषाओं में महत्वपूर्ण अंतर क्या है जानने के लिए देखें—C vs C++

Procedure Oriented Programming (POP) और Object Oriented Programming (OOP) में अंतर जानने के लिए देखें—POP vs OOP

Flowchart to convert binary to decimal

Binary to decimal conversion flowchart

C program to convert binary to decimal

#include<stdio.h>
int main()
{
    int binary, decimal=0, digit, base=1;
    printf("Enter binary number: ");
    scanf("%d",&binary);
    while(binary!=0)
    {
        digit=binary%10;
        decimal=digit*base+decimal;
        base=base*2;
        binary=binary/10;
    }
    printf("Decimal number = %d",decimal);
    return 0;
}

C++ program to convert binary to decimal

#include<iostream>
using namespace std;
int main()
{
    int binary, decimal=0, digit, base=1;
    cout<<"Enter binary number: ";
    cin>>binary;
    while(binary!=0)
    {
        digit=binary%10;
        decimal=digit*base+decimal;
        base=base*2;
        binary=binary/10;
    }
    cout<<"Decimal number = "<<decimal;
    return 0;
}

Output of C C++ program to convert binary to decimal

Enter binary number: 110100
Decimal number = 52
Enter binary number: 1001110
Decimal number = 78

More looping and Iteration programs in C and C++

  1. Generate series of natural numbers (while, for, do while)
  2. Generate series of natural numbers and their sum
  3. Generate series of odd numbers and find their sum
  4. Generate series of even numbers and find their sum
  5. Generate table of given number
  6. Find factorial of given number
  7. Find power of given number
  8. Generate multiplication table of given number
  9. HCF and LCM of two numbers
  10. Generating Fibonacci series
  11. Checking prime number
  12. Generating series of prime numbers
  13. Sum of digits of given number
  14. Reverse of digits of given number
  15. Checking palindrome number
  16. Checking Armstrong number
  17. Generating series of Armstrong numbers
  18. Convert binary to decimal
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer