December 9, 2023

CurledMark

curled up on the sofa

How to Run C Program in Command Prompt

In this article, you will learn how to Run C Program in Command Prompt. Moreover, there are programs screenshots that I have written in notepad and executed using a command prompt. Besides, Compiling the C code will turn the code into an executable C program. MinGW is one of the easiest options to install for Windows.

Install MinGW, a simple C compiler

  • Download MinGW from https://sourceforge.net/projects/mingw.
  • Double-click the downloaded file and follow the on-screen instructions to prepare the installation.
  • When you get to the MinGW Installation Manager window, you’ll see several packages in the upper-right panel.
  • Check the boxes next to “mingw32-base” and “MinGW-GCC-g++.”
  • Click the Installation menu and select Apply Changes.
  • Click Apply.

Add the compiler’s path to your system environment variables

This step makes it easier to run the compiler from the command prompt, as you won’t have to enter the full path to the GCC program.

  • Press the Windows key and type the environment. Click Edit the system environment variables in the search results and click the Environment Variables… button.
  • Select the “Path” option under “System variables” and click Edit…
  • Click New.
  • Type C:\MinGW\bin and click OK. Next Click OK again then again.

Open a Command Prompt window as an administrator

To do this, press the Windows key, type cmd, right-click Command Prompt, and then select Run as Administrator.

  • Once the prompt window is open, double-check that the compiler is installed properly (and that the environment variables are set) by running the command GCC -- version at the prompt.
  • If you already had a command prompt window open, close it and open another so the path you added

Use the cd command to go to the directory where your C program is saved

For example, if the program you want to compile is in D:\CPrograms, type cd D:\CPrograms and press Enter.

Run the GCC command to compile your C program.

 The syntax you’ll use is GCC filename. c -o filename.exe. This compiles the program and makes it executable.

  • Replace filename. c with the name of the file containing your C code, and filename.exe with the name you want to give the compiled program as well as make sure you give the compiled program a name that ends with .exe.
  • The -o flag specifies the output file.

Type the name of your new program and press Enter

For example, if you created a program called g1.exe, you can type g1.exe and This runs your C program from the command prompt.

Number Programs to show how to Run C Program in Command Prompt

In the images, we have executed the number programs and shown you the screenshots. However, there are three programs: Factorial, Fibonacci, and difference series.

Fibonacci series

Difference series

factorial number

You can also refer to this outbound link

https://www.edureka.co/blog/how-to-compile-c-program-in-command-prompt/

Also, read

https://curledmark.in/the-largest-number-program-in-an-array-in-c-programming/

https://curledmark.in/armstrong-number-and-arrays-in-c-programming/

https://curledmark.in/prime-reversepower-programs-in-c-programming/

The Book Of Five Rings Summary

The Blue Umbrella

How to Talk to Anyone by Leil Lowndes

Jonathan Livingston Seagull Book Summary

Your Brain on PORN Book Summary by Gary Wilson

THE IMMORTALS OF MELUHA By Amish Tripathi full summary

Eleven Minutes by Paulo Coelho Summary