- 1

Please give me a error solution in this program.

#include<stdio.h> #include<string.h> #include<math.h> int main() { char getbtd[]="1101.1010"; int length,dc=0,i=0,p1=0,p2=-1; float sum=0; length=strlen(getbtd); while(1) { if(getbtd[i]=='.') break; else dc++; i++; } for(i=dc-1;i>=0;i++) { sum = sum+((int)(getbtd[i]-'0')*pow(2,p1)); p1++; } for(i=dc+1;i<length;i++) { sum=sum+((int)(getbtd[i]-'0')*pow(2,p2)); p2--; } printf("Decimal No is:%f",sum); return 0; }

29th Jan 2021, 1:43 PM
Yash Makwana
Yash Makwana - avatar
6 Answers
+ 3
First of all the semicolon after return 0; Then second your for loop do not end.
29th Jan 2021, 2:07 PM
JaScript
JaScript - avatar
+ 2
Replace <studio.h> with <stdio.h> What is the code supposed to do? can you describe that? (Edit) Snippet modified.
29th Jan 2021, 2:13 PM
Ipang
+ 2
This loop should be: for(i=dc-1;i>=0;i--) { sum = sum+((int)(getbtd[i]-'0')*pow(2,p1)); p1++; } and the solution can be seen as follows: https://code.sololearn.com/cgIKDXzntAl9/?ref=app
29th Jan 2021, 3:40 PM
JaScript
JaScript - avatar
+ 2
Missing- semicolon after return 0; Loop do not end.
30th Jan 2021, 11:53 PM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
0
Replace <studio.h> with <stdio.h> What is the code supposed to do? can you describe that? To convert binary to decimal
29th Jan 2021, 2:21 PM
Yash Makwana
Yash Makwana - avatar
0
Yash, Do you have to do this manually? cause if not, you can use `strtol` function from <stdlib.h> https://en.cppreference.com/w/cpp/string/byte/strtol
29th Jan 2021, 2:38 PM
Ipang