Binary to decimal conversion in programing language, Lecture notes of Object Oriented Programming

This document has the program code that will convert input if it is in binary then convert it into decimal

Typology: Lecture notes

2018/2019

Available from 07/21/2023

Jennifer_0000
Jennifer_0000 🇵🇰

3 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include <stdio.h>
#include <math.h >
int main()
{
int n;
int d=0, r=0, s=0;
printf("Enter a Binary Number\n");
scanf("%d", &n);
while(n)
{
r = n % 10;
if(r)
{
d = d + (pow(2, s) );
}
n = n / 10;
s++;
}
printf("Decimal number is ");
printf("%d\n", d);
return 0;
}

Partial preview of the text

Download Binary to decimal conversion in programing language and more Lecture notes Object Oriented Programming in PDF only on Docsity!

#include <stdio.h> #include <math.h > int main() { int n; int d=0, r=0, s=0; printf("Enter a Binary Number\n"); scanf("%d", &n); while(n) { r = n % 10; if(r) { d = d + (pow(2, s) ); } n = n / 10; s++; } printf("Decimal number is "); printf("%d\n", d); return 0; }