Tech Study

Write C Program to convert binary number to decimal

Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
#include <math.h>
 
//Function declartion
int convertBinaryToDecimal(long long n);
 
int main()
{
    long long n;
    printf("Enter a binary number: ");
    // Inputting number from user
    scanf("%lld", &n);
    //Printing binary number to decimal
    printf("%lld in binary = %d in decimal", n, convertBinaryToDecimal(n));
    return 0;
}
 
int convertBinaryToDecimal(long long n)
{
    int decimalNumber = 0, i = 0, remainder;
    while (n!=0)
    {
        remainder = n%10;
        n /= 10;
        decimalNumber += remainder*pow(2,i);
        ++i;
    }
    return decimalNumber;
}

Result

Write C Program to convert binary number to decimal
Write C Program to convert binary number to decimal

TaggedWrite C Program to convert binary number to decimal

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more