Last Updated: 10 Feb, 2021

Set Bits

Easy
Asked in companies
AmazonD.E.ShawGoogle inc

Problem statement

Write a program to count the number of 1's in the binary representation of an integer.

Input format :
 The only line of input contains a single integer N.
Output format :
The only line of the output prints the total number of 1.
Constraints
1 <= N <= 100

Approaches

01 Approach

  • Here we are converting the number into binary, and during the conversion, we are checking the remainder part.
  • If it is 1, then we increment the value of count by 1.