How to install composer on windows and configure to work with Drupal

Step-1 

Go to the Drupal root directory ( e.g If you have installed XAMPP, It may be in c:/xampp/htdocs/drupal ) 

Step-2

Inside that directory press ctrl+shift on keyboard and right click simultaneously to open a Command prompt window directly.

Step-3 

Type this command and press enter :                                                                                                                              php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

Step-4

Type this command and press enter :                                                                                                                               echo php "%~dp0composer.phar" %* > composer.bat

Step-5

Your composer is successfully configured. You can execute any command now .

E.g to download a module and its dependencies execute this:

>composer require drupal/search_api_location 

>drush en search_api_location 

Remember the composer is not configured to access from any location i.e you have to access it by going to root directory always. e.g inside your Drupal root directory open the command window by pressing ctrl+shift+right mouse click and type any command like  " composer  update drupal/modulename " and press enter.

More Read: https://www.drupal.org/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies