- Related Questions & Answers
- C# program to check if there are K consecutive 1’s in a binary number
- Python Program to Count number of binary strings without consecutive 1’
- C/C++ Program to Count number of binary strings without consecutive 1’s?
- Program to Count number of binary strings without consecutive 1’s in C/C++?
- 1’s and 2’s complement of a Binary Number?
- Maximum length of consecutive 1’s in a binary string in Python using Map function
- Count Binary String without Consecutive 1's
- Binary representation of next greater number with same number of 1’s and 0’s in C Program?
- Count number of binary strings without consecutive 1's in C
- C# program to find the length of the Longest Consecutive 1’s in Binary Representation of a given integer
- Java program to find the length of the Longest Consecutive 1’s in Binary Representation of a given integer
- Count the number of 1’s and 0’s in a binary array using STL in C++
- Count 1’s in a sorted binary array in C++
- Python program to find the length of the largest consecutive 1's in Binary Representation of a given string.
- Count number of binary strings of length N having only 0’s and 1’s in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

First we take a user input string with the combination of 1’s and 0’s.then create a new string with 1’s,then check if there is any p number of consecutive 1’s is present or not. If present then display FOUND otherwise NOTFOUND.

Binary number ::1111001111 Enter consecutive 1’s :3 Consecutive 1's is Found

Step 1: input a string with the combination of 1’s, it’s stored in the variable X and 0’s and p is the consecutive 1’s in a binary number. Step 2: form a new string of p 1’s. newstring=”1”*p Step 3: check if there is p 1’s at any position. If newstring in X Display “FOUND” Else Display “NOT FOUND” End if

# To check if there is k consecutive 1's in a binary number def binaryno_ones(n,p): # form a new string of k 1's newstr = "1"*p # if there is k 1's at any position if newstr in n: print ("Consecutive 1's is Found") else: print (" Consecutive 1's is Not Found") # driver code n =input("Enter Binary number ::") p = int(input("Enter consecutive 1's ::")) binaryno_ones(n, p)

Enter Binary number ::1111001111 Enter consecutive 1's ::3 Consecutive 1's is Found

Advertisements