What is Programming?
Programming is the process of creating instructions for a computer to perform specific tasks. It is done using programming languages like C, Python, Java, etc.
📌 Purpose:
- To solve problems efficiently
- Automate tasks
- Create applications, websites, games, software tools
2. Introduction to C
C is a powerful, general-purpose programming language developed by Dennis Ritchie in 1972 at Bell Labs. It is widely used for system software, compilers, operating systems, and embedded systems.
🔑 Features:
- Procedural language
- Fast and efficient
- Portable and flexible
- Foundation of many modern languages (like C++, Java)
3. Basic Syntax, Data Types, Variables
✅ Syntax:
Rules that define how C code should be written.
✅ Variables:
Containers to store data.
cCopyEditint age = 20;
float salary = 30000.50;
char grade = 'A';
✅ Data Types:
| Type | Keyword | Example |
|---|---|---|
| Integer | int | int x = 10; |
| Decimal | float | float y = 5.5; |
| Character | char | char c = 'A'; |
4. Input/Output (printf, scanf)
printf()– Output functionscanf()– Input function
📘 Example:
cCopyEdit#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You are %d years old.\n", age);
return 0;
}
5. Operators
✅ Types:
- Arithmetic:
+,-,*,/,% - Relational:
==,!=,>,<,>=,<= - Logical:
&&,||,!
📘 Example:
cCopyEditint a = 5, b = 3;
printf("Sum: %d\n", a + b); // 8
printf("Is a > b? %d\n", a > b); // 1 (true)
6. Conditional Statements
These help make decisions in code.
✅ if, else, else if, switch
📘 Example (if-else):
cCopyEditint age = 18;
if (age >= 18) {
printf("You are an adult.");
} else {
printf("You are a minor.");
}
📘 Example (switch):
cCopyEditint day = 2;
switch(day) {
case 1: printf("Monday"); break;
case 2: printf("Tuesday"); break;
default: printf("Invalid day");
}
7. Loops
Used to execute code repeatedly.
✅ Types:
forwhiledo-while
📘 Example (for loop):
cCopyEditfor(int i = 1; i <= 5; i++) {
printf("%d ", i); // Output: 1 2 3 4 5
}
📘 Example (while loop):
cCopyEditint i = 1;
while(i <= 5) {
printf("%d ", i);
i++;
}
📘 Example (do-while loop):
cCopyEditint i = 1;
do {
printf("%d ", i);
i++;
} while(i <= 5);
8. Simple Programs
📘 1. Calculator (Add two numbers):
cCopyEdit#include <stdio.h>
int main() {
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum = %d\n", sum);
return 0;
}
📘 2. Area of a Circle:
cCopyEdit#include <stdio.h>
#define PI 3.14
int main() {
float radius, area;
printf("Enter radius: ");
scanf("%f", &radius);
area = PI * radius * radius;
printf("Area = %.2f\n", area);
return 0;
}
✅ Summary Table
| Topic | Description | Example Function |
|---|---|---|
| What is Programming? | Writing instructions for a computer | — |
| Introduction to C | Overview and features of C language | — |
| Syntax & Variables | Declaring & using variables | int x = 5; |
| Input/Output | Taking input, showing output | scanf, printf |
| Operators | Performing operations | +, >, && |
| Conditional Statements | Making decisions | if, switch |
| Loops | Repeating code | for, while |
| Simple Programs | Basic coding tasks | calculator, area |