
STEP 1
First of all we need to install the build-essential packages. To copy the following commands in linux terminal.
sudo apt-get install build-essential
STEP 2
Secondly open any text editor type your program code and save it in .c extension.
Sample code:
#include <stdio.h>
int main() {
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
for (i = 2; i <= n / 2; ++i) {
// condition for non-prime
if (n % i == 0) {
flag = 1;
break;
}
}
if (n == 1) {
printf("1 is neither prime nor composite.");
}
else {
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
}
return 0;
}
Step 3
To compile the c program with gcc compiler. We need to open the program folder when you save your program code and right click in blank space there is a option ‘open in terminal’ is shown. You just click that option. In your Terminal, enter the following command in order to make an executable version of the program you have written:
gcc [programName].c -o programName
for example
gcc primenumber.c -o primenumber
If you did any mistake in program simply shown in terminal otherwise this code can execute the program code.
Step 4
The final step is to run the compiled C program. Use the following syntax to do so:
./programName
for example
./primenumber
I hope you all are understand how to run c program code in linux terminal, If you have doubts please comment below this blog. Thank You…