In this program I need to count the number of 1's present in the binary number after converting the decimal base. Here is the code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main ()
{
char valor[1000], tmp;
long long int count, valor_i, valor_c = 0, r_div, i, count2;
scanf("%lld", &valor_i);
count = 0;
i = 0;
while (i != 1)
{
r_div = valor_i / 2;
if (r_div < 2)
{
i = 1;
if(valor_i % 2 == 0)
{
valor[count] = '0';
}
else
{
valor[count] = '1';
}
if(r_div == 0)
{
valor[count + 1] = '0';
}
else
{
valor[count + 1] = '1';
}
valor[count + 2] = '#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main ()
{
char valor[1000], tmp;
long long int count, valor_i, valor_c = 0, r_div, i, count2;
scanf("%lld", &valor_i);
count = 0;
i = 0;
while (i != 1)
{
r_div = valor_i / 2;
if (r_div < 2)
{
i = 1;
if(valor_i % 2 == 0)
{
valor[count] = '0';
}
else
{
valor[count] = '1';
}
if(r_div == 0)
{
valor[count + 1] = '0';
}
else
{
valor[count + 1] = '1';
}
valor[count + 2] = '%pre%';
}
else
{
if (valor_i % 2 == 0)
{
valor[count] = '0';
}
else
{
valor[count] = '1';
}
}
count++;
valor_i = r_div;
}
count2 = strlen(valor) - 1;
for(count = 0; count == count2 || count < count2; count++)
{
tmp = valor[count];
valor[count] = valor[count2];
valor[count2] = tmp;
count2--;
}
printf("%s\n", valor);
return 0;
}
';
}
else
{
if (valor_i % 2 == 0)
{
valor[count] = '0';
}
else
{
valor[count] = '1';
}
}
count++;
valor_i = r_div;
}
count2 = strlen(valor) - 1;
for(count = 0; count == count2 || count < count2; count++)
{
tmp = valor[count];
valor[count] = valor[count2];
valor[count2] = tmp;
count2--;
}
printf("%s\n", valor);
return 0;
}