/* Write A C Program To Accept A Decimal Number

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View /* Write A C Program To Accept A Decimal Number as PDF for free.

More details

  • Words: 179
  • Pages: 1
/* Write a C program to accept a decimal number and conert it binary * and count the number of 1's in the binary number #include <stdio.h> void main() { long num, dnum, rem, base = 1, bin = 0, no_of_1s = 0; printf("Enter a decimal integer\n"); scanf("%ld", &num); dnum = num; while( num > 0 ) { rem = num % 2; if ( rem == 1 ) /*To count no.of { no_of_1s++; } bin = bin + rem * base; num = num / 2 ; base = base * 10; } printf("Input number is = printf("Its Binary equivalent is = printf("No.of 1's in the binary number is = }

1s*/

%d\n", dnum); %ld\n", bin); %d\n", no_of_1s);

/* End of main() */

/*-------------------------------------------------Output Enter a decimal integer 75 Input number is = 75 Its Binary equivalent is = 1001011 No.of 1's in the binary number is = 4 RUN2 Enter a decimal integer 128 Input number is = 128 Its Binary equivalent is = 10000000 No.of 1's in the binary number is = 1 -----------------------------------------------------*/

* */

Related Documents