I wrote a program to check the max no. of consecutive 1s in binary form of given decimal no. but sometimes it is given wrong output.
For example if I enter 439 I get 4 as output but correct output is 3.
............... .......c
............... .........
For example if I enter 439 I get 4 as output but correct output is 3.
............... .......c
Code:
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int n,max=0,count=0;
scanf("%d",&n);
while(n!=0)
{
if(n%2!=0)
{
count++;
}
else
{
if(max<count)
{
max=count;
count=0;
}
}
n/=2;
}
if(count>max)
max=count;
printf("%d",max);
return 0;
}
Comment