Here is a full c programming tutorial:
https://www.youtube.com/watch?v=-CpG3oATGIs&t=2s
This is a quite good one.
A simple hello world c program is like this:
#include <stdio.h>
int main () {
printf("Hello World! \n");
return 0;
}
Then to compile it:
gcc hello.c -o hello
To run;
./hello
If you want to have some math function, you need to add math.h
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main() {
const double a=3.1;
double b;
b=cos(a);
printf("%f \n",b);
return 0;
}
To compile it:
gcc -o 5th 5th.c -lm
i.e. you need to add -lm in the end.
#include <math.h>
#include <stdlib.h>
int main() {
const double a=3.1;
double b;
b=cos(a);
printf("%f \n",b);
return 0;
}
To compile it:
gcc -o 5th 5th.c -lm
i.e. you need to add -lm in the end.
No comments:
Post a Comment