We can easily code c using linux terminal commandline bellow showing tips
At first we have to enter desktop file so use command
$cd Desktop
$touch helloworld.c
next enter the file helloworld.c and code inside the file and save
that code:
#include <stdio.h>
int main() {
printf("i am ibnsina himel!\\n");
return 0;
}
Now we have to put c running command
gcc helloworld.c -o helloworld
./helloworld
Next we can see that the c file starts executing
to fix this problem we have to do some changes
sudo apt update
sudo apt install gcc -y
gcc --version
gcc helloworld.c -o helloworld
./helloworld
Another example of calculator app using c in linux terminal
tab exit you will get saving option
now put the executing command as before,mission successful
code that used to make simple calculator:
#include <stdio.h>
int main() {
double num1, num2, result;
char operator;
// Taking user input
printf("Enter first number: ");
scanf("%lf", &num1);
printf("Enter an operator (+, -, *, /): ");
scanf(" %c", &operator);
printf("Enter second number: ");
scanf("%lf", &num2);
// Performing operation
switch (operator) {
case '+':
result = num1 + num2;
printf("Result: %.2lf\n", result);
break;
case '-':
result = num1 - num2;
printf("Result: %.2lf\n", result);
break;
case '*':
result = num1 * num2;
printf("Result: %.2lf\n", result);
break;
case '/':
if (num2 != 0)
result = num1 / num2;
else {
printf("Error: Division by zero is not allowed.\n");
return 1;
}
printf("Result: %.2lf\n", result);
break;
default:
printf("Error: Invalid operator.\n");
}
return 0;
}
Thus you can do c program on linux terminal without any c compiler as codeblocks
0 Comments