Posts

C Program To Accept The String Starting With 01 And Ending With 011 | C Programming

Image
C Program To Accept The String Starting With 01 And Ending With 011 #include <stdio.h> #include <string.h> int main () {     char str [ 10 ];     int len, i, q = 0 ;     printf ( "enter the string which only contain 0 and 1 \n " );     scanf ( " %s " , str);     len = strlen (str);     for (i = 0 ; i <= len; i++)     {         if ( str [i] == '0' && q == 0 )             q = 1 ;         else if ( str [i] == '1' && q == 0 )             q = 6 ;         else if ( str [i] == '0' && q == 1 )             q = 6 ;         else if ( str [i] == '1' && q == 1 )             q = 2 ;         else if ( str [i] == '0' && q == 2 )             q = 3 ;         else if ( str [i] == '1' && q == 2 )             q = 2 ;         else if ( str [i] == '0' && q == 3 )             q = 3 ;         else if ( str [i] == '1' &&a

C Program To Accept The String Starting With ab And Ending With abb | C Programming

Image
C Program To Accept The String Starting With ab And Ending With abb  #include <stdio.h> #include <string.h> int main ( int argc , char const * argv []) {     char str [ 10 ];     int len, i, q = 0 ;     printf ( "enter the string which only contain a and b \n " );     scanf ( " %s " , str);     len = strlen (str);     for (i = 0 ; i <= len; i++)     {         if ( str [i] == 'a' && q == 0 )             q = 1 ;         else if ( str [i] == 'b' && q == 0 )             q = 6 ;         else if ( str [i] == 'a' && q == 1 )             q = 6 ;         else if ( str [i] == 'b' && q == 1 )             q = 2 ;         else if ( str [i] == 'a' && q == 2 )             q = 3 ;         else if ( str [i] == 'b' && q == 2 )             q = 2 ;         else if ( str [i] == 'a' && q == 3 )             q = 3 ;         else i

Variables in C

Image
Variables in C Programmings:- "Variable in C" variables names are case sensitive whose value can change any time. It is a memory location used to store data value. A variable name in C variables should be carefully chosen so that its use is reflected in a useful way in the entire program.  Rules for declaring variables in C Programming:- They must always begin with a letter, although some systems permit underscore as the first character. The length of a variable must not be more than 8 characters. White space is not allowed and A variable should not be a Keyword It should not contain any special characters.  In C variables A variable declaration provides assurance to the compiler that there exists a variable with the given type and name so that the compiler can proceed for further compilation without requiring the complete detail about the variable. A variable definition has its meaning at the time of compilation only, the compiler needs actual variable

C Program To Accept The String That Ends With 01 | C Programming

Image
C Program To Accept The String That Ends With 01 #include <stdio.h> #include <math.h> #include <string.h> int main () {     char s [ 100 ];     int i = 0 , q = 0 , l;     printf ( "Enter stringover {0,1}: \n " );         scanf ( " %s " ,s);     l = strlen (s);     for (i = 0 ; s [i] != ' \0 ' ; i++)     {         if ( s [i] == '0' && q == 0 )         {             if (i == (l - 2 ))                 q = 1 ;             else                 q = 0 ;         }         else if ( s [i] == '1' && q == 0 )             q = 0 ;         else if ( s [i] == '1' && q == 1 )             q = 2 ;     }     if (q == 2 )     {         printf ( "Accepted. \n\n " );     }     else         printf ( "Rejected." );     return 0 ; } OUTPUT #1 OUTPUT #2 Related Posts C Program To Accept The String Having Even Length | C Programming C Program To Accept The String T

C Program To Accept The String Starting With 01 | C Programming

Image
C Program To Accept The String Starting With 01 #include <stdio.h> #include <string.h> int main () {     char str [ 10 ];     int len, i, q = 0 ;     printf ( "enter the string which only contain 0 and 1 \n " );     scanf ( " %s " , str);     len = strlen (str);     for (i = 0 ; i <= len; i++)     {         if ( str [i] == '0' && q == 0 )             q = 1 ;         else if ( str [i] == '1' && q == 0 )             break ;         else if ( str [i] == '1' && q == 1 )             q = 2 ;         else if ( str [i] == '0' && q == 1 )             break ;         else if ( str [i] == '0' && q == 2 )             q = 2 ;         else if ( str [i] == '1' && q == 2 )             q = 2 ;     }     if (q == 2 )         printf ( "Given string is accepted \n " );     else         printf ( "Given string is not accepted \n "

C Program For Bubble Sort | C Programming

Image
C Program For Bubble Sort by Generating Random Numbers and Using time.h Function #include <stdio.h> #include <time.h> #include <stdlib.h> void bubble_sort ( int [], int ); int main () {     int list [ 100 ], n , i ;     time_t t ;     printf ( "Enter the max number \n " );     scanf ( " %d " , & n );     srand (( unsigned ) time (& t ));     for ( i = 0 ; i < n ; i ++)     {         list [ i ] = rand () % 100 ;     }     for ( i = 0 ; i < n ; i ++)     {         printf ( " %d \t " , list [ i ]);     }     bubble_sort ( list , n );     printf ( " \n\n Time taken to complete the bubblesort %u \n " , clock () / CLOCKS_PER_SEC);     printf ( " \n The sorted list is:" );     for ( i = 0 ; i < n ; i ++)         printf ( " %d \t " , list [ i ]);     return 0 ; } void bubble_sort ( int list [], int n ) {     int temp , i , j ;     for ( i = 0 ; i < n ; i ++)     {    

C Program To Accept The String Having Length At Least Two | C Programming

Image
C Program To Accept The String Having Length At Least Two #include <stdio.h> #include <string.h> int main () {     char str [ 10 ];     int len, i, q = 0 ;     printf ( "Enter the string which only contain a and b \n " );     scanf ( " %s " , str);     len = strlen (str);     for (i = 0 ; i <= len; i++)     {         if ( str [i] == 'a' && q == 0 )             q = 1 ;         else if ( str [i] == 'b' && q == 0 )             q = 1 ;         else if ( str [i] == 'a' && q == 1 )             q = 2 ;         else if ( str [i] == 'b' && q == 1 )             q = 2 ;         else if ( str [i] == 'a' && q == 2 )             q = 3 ;         else if ( str [i] == 'b' && q == 2 )             q = 3 ;         else if ( str [i] == 'a' && q == 3 )             q = 3 ;         else if ( str [i] == 'b' && q == 3