top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Find amount of numbers that are between 1 and 100 inclusive, when converted to binary have a digit sum of less than 5?

+1 vote
252 views
Find amount of numbers that are between 1 and 100 inclusive, when converted to binary have a digit sum of less than 5?
posted Jun 14, 2016 by anonymous

Share this puzzle
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

There are 87 decimal numbers from 1 to 100 (including 1 and 100)
That have their binary version's digits add upto 4 or as given in the question less than 5.

answer Jun 18, 2016 by Tejas Naik
Here is the c code I used.
#include <stdio.h>
#include<math.h>
int main ()
{
    int a,b,c,d,count;
    count=0;
    for (a=1;a<101;a++)
    {
        b=a;
        d=0;
        while (b>0)
        {
            c=b%2;
            b=b/2;
            d=d+c;
        }
       if (d<5)
        {
            count=count+1;
        }
    }
    
   printf("There are %d many decimal numbers which have thier binary version's digits add upto or lesser than 5",count);
    
}
i have yet to study the listing but KUDOS
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...