Posts

Reverse an array of n element

  #include< stdio.h > int   main () {      int   n ;      scanf ( "%d" ,& n );      int   a [ n ], temp , x = n - 1 ;      for ( int   i = 0 ; i < n ; i ++)      {          scanf ( "%d" ,& a [ i ]);          }      for ( int   e = 0 ; e < n / 2 ; e ++)      {          temp = a [ e ];          a [ e ]= a [ x ];          a [ x ]= temp ;          x --;      }      for ( int   i = 0 ; i < n ; i ++)      {          printf ( "%d " , a [ i ]);     ...

Number guessing game(Project 1)

  #include   < stdio.h > #include   < stdlib.h > #include   < time.h > void   main () {      printf ( " Welcome to the Number Guessing Game \n " );      printf ( " Are you ready to play the game. \n " );      printf ( " If yes then enter 1 if no then enter anything beside 1 \n " );      int   c ;      scanf ( " %d " ,   & c );      if   ( c   ==   1 )      {          printf ( " The number is between 1-100 \n " );          int   n ,   t , count = 0 ;          srand ( time ( 0 ));        ...

Swapping

macro:- #define SWAP(x,y,t) ((t) = (x), (y)=(x), (y)=(t))   #include   < stdio.h > #include   < string.h > void   main () {      int   n , temp = 0 , x , y ;      printf ( " Enter the amount of numbers to be entered: \n " );      scanf ( " %d " ,& n );      int   a [ n ];   //arrau Creation      //Filling the array      for ( int   i = 0 ; i < n ; i ++)      {          printf ( " Enter the %d number: " , i + 1 );          scanf ( " %d " ,& a [ i ]);      }      printf ( " Enter the first index: \n " );      scanf ( " %d " ,& x );      printf ( " En...

Selection sorting

  #include   < stdio.h > #include   < string.h > void   main () {      int   n , temp = 0 , o = 1 ;      printf ( " Enter the amount of numbers to be entered: \n " );      scanf ( " %d " ,& n );      int   a [ n ];   //arrau Creation      //Filling the array      for ( int   i = 0 ; i < n ; i ++)      {          printf ( " Enter the %d number: " , i + 1 );          scanf ( " %d " ,& a [ i ]);      }      //sorting      for ( int   k = 0 ; k < n - 1 ; k ++)      {          for ( int   j = o ; j < n ; j ++)  ...