google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c program to convert a given binary into decimal - 2nd puc computer science

Write a c program to convert a given binary into decimal

Write a c program to convert a given binary into decimal

write a c program to convert a given binary number into decimal number

#include<stdio.h>

#include<conio.h>

void main()

{

int n,dec=0,base=1,r;

clrscr();

printf("Enter the binary number: ");

scanf("%d",&n);

while(n>0)

{

r=n%10;

dec=dec+r*base;

n=n/10;

base=base*2;

}

printf("The decimal number=%d",dec);

getch();

}

Output:

Enter the binary number: 1100

The decimal number=12                                                           


Write a c program to convert a given binary into decimal Write a c program to convert a given binary into decimal Reviewed by Vision Academy on December 22, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.