Program for convert binary to decimal - C-Tutorial

Latest

Sunday, 8 December 2019

Program for convert binary to decimal


/*  Program for convert binary to decimal */

#include <stdio.h>
#include <math.h>

void main()
{
    long int n;
    int dec = 0, temp = 0, r;

    clrscr();

    printf("Enter a binary number: ");
    scanf("%ld", &n);

    while (n!=0)
    {
        r = n % 10;
        n = n / 10;
        dec = dec + r * pow(2,temp);
        temp++;
    }

    printf("\n\n Equivalent decimal number is: %d", dec);

   getch();
}

No comments:

Post a Comment