Hi,
I need to count number of ones and zeros in the following binary number: 11000111101011101100011100011011.
Issue: It is correctly counting number of ones uptill 17 bits i-e 11000111101011101 . But when i increase my binary number it gives false answer.
Try: I have already use the "long long int" but no use.
below is the C code which i tried .
#include<stdio.h>
int main()
{
int r, ones=0, zeroes=0;
long int n;
printf("Enter a Binary Number ");
fflush( stdout );
scanf("%ld", &n);
while(n!=0)
{
r=n%10;
if(r==1)
ones++;
if(r==0)
zeroes++;
n=n/10;
}
printf("\nNumber of ones are %d", ones);
getchar();
return 0;
}