AbdulFathaah

binary to decimal

Sep 29th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. /* program to convert binary to decimal*/
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<math.h>
  5. void main()
  6. {
  7. char ch;
  8. do {
  9. int n,digit=0,k=0,rem=0;
  10. clrscr();
  11. printf("\nEnter a binary number: ");
  12. scanf("%d",&n);
  13. while(n!=0)
  14. {
  15. rem=n%10;
  16. digit=digit+rem*pow(2,k);
  17. k++;
  18. n/=10;
  19. }
  20. printf("Converted Decimal:%d",digit);
  21. printf("\nDo you want to continue? (y/n)");
  22. scanf("%c",&ch);
  23. }
  24. while(ch == 'y'|| ch == 'Y');
  25. getch();
  26. }
  27. 
Advertisement
Add Comment
Please, Sign In to add comment