C PROGRAMMING
TUTORIAL
Table of Contents
Chapter 1: Your First C Program .......... [Link]
Chapter 2: Variables .......... [Link]
Chapter 3: Format Specifiers .......... [Link]
Chapter 4: Arithmetic Operators .......... [Link]
Chapter 5: If Statements .......... [Link]
Chapter 1: Your First C Program ([Link])
Let's begin our journey with the classic "Hello World" program. This introduces
the structure of a basic C program.
#include
int main() {
printf("Hello, World!");
return 0;
}
Explanation: - #include imports the Standard I/O library. - int main() is the
program entry point. - printf() prints output to the console. - return 0; signals
successful program termination.
Chapter 2: Variables ([Link])
Variables store information that can change while your program runs.
#include
int main() {
int age = 21;
float gpa = 3.8;
char grade = 'A';
printf("Age: %d\n", age);
printf("GPA: %.2f\n", gpa);
printf("Grade: %c\n", grade);
return 0;
}
Explanation: - int: whole numbers - float: decimal numbers - char: single
characters Tip: Always initialize variables before using them.
Chapter 3: Format Specifiers ([Link])
Format specifiers control how data appears when printed.
#include
int main() {
int score = 95;
float pi = 3.14159;
char initial = 'B';
char name[] = "Bro Code";
printf("Score: %d\n", score);
printf("Pi: %.2f\n", pi);
printf("Initial: %c\n", initial);
printf("Name: %s\n", name);
return 0;
}
Common Format Specifiers: %d - integer %f - float %.2f - float with 2 decimals %c
- character %s - string
Chapter 4: Arithmetic Operators ([Link])
C supports arithmetic operations like addition, subtraction, multiplication, and
division.
#include
int main() {
int a = 10, b = 3;
printf("Sum: %d\n", a + b);
printf("Difference: %d\n", a - b);
printf("Product: %d\n", a * b);
printf("Quotient: %d\n", a / b);
printf("Remainder: %d\n", a % b);
return 0;
}
Operators: + Addition - Subtraction * Multiplication / Division % Modulus
(remainder) Note: Integer division truncates results. Use float variables for
precision.
Chapter 5: If Statements ([Link])
Conditional statements allow decision-making in programs.
#include
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age;);
if (age >= 18) {
printf("You are an adult.\n");
} else {
printf("You are a minor.\n");
}
return 0;
}
Explanation: - if(condition) checks whether it's true. - else executes when the
condition is false. - Relational operators: >, <, >=, <=, ==, != Try adding else if for
more conditions!