C Online Compiler
Example: C program to find all the patterns of 0(1+)0 in the given string
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C program to find all the patterns of 0(1+)0 in the given string #include <stdio.h> #include <string.h> // @This function will find the pattern int findPattern(char str[]) { char last = str[0]; int i = 1, c = 0; // c is the counter part while (i < strlen(str)) { if (str[i] == '1' && last == '0') { while (str[i] == '1') i++; if (str[i] == '0') c++; } last = str[i]; i++; } return c; } // @It's the driver function int main() { char str[50]; printf("Enter the string: "); gets(str); printf("\nThe Number of patterns found: %d\n", findPattern(str)); return 0; }
1001001001
Output
Clear
ADVERTISEMENTS