C Code Examples
1. Hello World
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
2. Fibonacci Sequence
#include <stdio.h>
int main() {
int n = 10, t1 = 0, t2 = 1, nextTerm;
printf("Fibonacci Series: ");
for (int i = 1; i <= n; ++i) {
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}
Real C Compilation Instructions
To actually compile C code on your computer:
Windows:
- Install MinGW-w64
- Save your code as
program.c
- Run in command prompt:
gcc program.c -o program
program.exe
Linux/Mac:
- Install GCC:
sudo apt install gcc # Ubuntu/Debian
brew install gcc # Mac
- Compile and run:
gcc program.c -o program
./program
Online Compilers:
0 Comments