Posts

Click the Follow Button

TIC - TAC - TOE

  def main (): # The main function     introduction = intro()     board = create_grid()     pretty = printPretty(board)     symbol_1, symbol_2 = sym()     full = isFull(board, symbol_1, symbol_2) # The function that starts the game is also in here.         def intro (): # This function introduces the rules of the game Tic Tac Toe     print ( "Hello! Welcome to Pam's Tic Tac Toe game!" )     print ( " \n " )     print ( "Rules: Player 1 and player 2, represented by X and O, take turns "           "marking the spaces in a 3*3 grid. The player who succeeds in placing "           "three of their marks in a horizontal, vertical, or diagonal row wins." )     print ( " \n " )     input ( "Press enter to continue." )     print ( " \n " ) def create_grid (): # This function creates a blank playboard  ...

Prime and not prime number

 PROGRAM: #include <stdio.h> int main () {     int i = 2 , n , p , a ;     printf ( "Enter a number: " );     scanf ( " %d " , & n );     // for (i = 2; i< n; i++)     // {     //     p = n%i;     //     if (p==0)     //     {     //         a = 1;     //     }     //     else     //     continue;             // }     while ( i < n )     {         p = n % i ;         if ( p == 0 )         {             a = 1 ;             break ;         }       i ++ ;     }     if ( a == 1 )         printf ( "it is not a prime number"...

Number pyramid by for loop

 PROGRAM: #include <stdio.h> int main () {     for ( int i = 1 ; i <= 5 ; i ++ )     {         for ( int j = 1 ; j <= i ; j ++ )         {             printf ( " %d " , j );         }         printf ( " \n " );             }     return 0 ; } OUTPUT: 1 12 123 1234 12345

number pyramid

 PROGRAM: #include <stdio.h> int main () {     int n ;     printf ( "enter the number: " );     scanf ( " %d " , & n );     for ( int i = 1 ; i <= n ; i ++ )     {         for ( int j = 1 ; j <= i ; j ++ )         {             printf ( " %d " , i );         }         printf ( " \n " );             }     return 0 ; } OUTPUT: enter the number: 5 1 22 333 4444 55555

do_while loop is to do something again and again

PROGRAM: #include <stdio.h> int main () {     int n ;     // do - while loop is to do something again and again     do     {     printf ( "enter the number- \n " );     scanf ( " %d " , & n );     }     while ( n < 1 );     for ( int i = 0 ; i < n ; i ++ )     {         for ( int j = 0 ; j < n ; j ++ )         {             printf ( "*" );         }         printf ( " \n " );     } }  OUTPUT: enter the number- 5 ***** ***** ***** ***** *****

C: Write a C program to display diagonal pyramid(upside-down) in a specific set of line insert by the user.

 PROGRAM: #include <stdio.h> int main () {     int n ;     printf ( "enter the number: " );     scanf ( " %d " , & n );     for ( int i = n ; i >= 1 ; i -- )     {         for ( int j = i ; j >= 1 ; j -- )         {             printf ( " %d " , j );         }         printf ( " \n " );             }     return 0 ; } OUTPUT:                  enter the number: 8 87654321 7654321 654321 54321 4321 321 21 1

C: Write a C program to display diagonal * pyramid(upside-down) in a specific set of line insert by the user.

 PROGRAM: #include <stdio.h> int main () {     int n ;     printf ( "enter the number: " );     scanf ( " %d " , & n );     for ( int i = 1 ; i <= n ; i ++ )     {         for ( int j = n ; j >= i ; j -- )         {             printf ( "*" );         }         printf ( " \n " );             }     return 0 ; } OUTPUT:                    enter the number: 10 ********** ********* ******** ******* ****** ***** **** *** ** *