Write a C program that reads an integer from stdin and find

Write a C program that reads an integer from stdin, and find the length of the longest consecutive sequence of one bits in the binary representation the the number. The output should be one number on one line. Do not print a prompt. Create a subdirectory of your home directory named jan30 (note the case). Save your solution in that directory in a file named bitseq. c Your program is due Monday January 30 at 4:00PM. You will not receive any credit if your program is late, has the wrong filename or is in the wrong directory.

Solution

#include<stdio.h>

int maxConsecutiveOnes(int x)
{
// Initialize result
int count = 0;

// Count the number of iterations to
// reach x = 0.
while (x!=0)
{
// This operation reduces length
// of every sequence of 1s by one.
x = (x & (x << 1));

count++;
}

return count;
}

// Driver code
int main()
{
   int n, count;
   printf(\"Pleas Enter the number \");
   scanf(\"%d\",&n);
count=maxConsecutiveOnes(n);
printf(\"longest consecutive sequence of 1s is : %d \",count);
return 0;
}

 Write a C program that reads an integer from stdin, and find the length of the longest consecutive sequence of one bits in the binary representation the the nu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site