Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
431 B
5
Indexable
Never
#include <iostream>
using namespace std;
int bit(unsigned int a, unsigned int c)
{
	unsigned int d = 0;
	while (a)
	{
		d = a % 2;
		c = (10 * c) + d;
		a /= 2;
	}
	int p = c;
	c = 0;
	while(p)
	{
		c = c * 10 + p % 10;
		p /= 10;
	}
	return c;
}
int main()
{
	unsigned int a, c = 0, b, i = 0;
	cin >> a;
	int d = bit(a, c);
	while (d)
	{
		b = d % 10;
		if (b == 1) i++;
		d /= 10;
	}
	cout << i;
}
Leave a Comment