C Programming Practice: Hello World, Calculator, and Swap Numbers
This tutorial provides beginner-friendly practice programs in C programming, including a "Hello World" program, a simple calculator, and swapping two numbers. These examples help beginners understand program structure, input/output, operators, and variables.
1. Hello World Program
Description
The first program in C that demonstrates basic syntax and output using printf().
Code Example
Output
2. Simple Calculator
Description
A program to perform basic arithmetic operations (+, -, *, /) using user input and switch statement.
Code Example
Sample Output
3. Swap Two Numbers
Description
A program to swap the values of two variables using:
- A temporary variable
- Without temporary variable
Method 1: Using Temporary Variable
Method 2: Without Temporary Variable
Sample Output
Key Points to Remember
- Always include
<stdio.h>for I/O functions - Use
return 0;to indicate successful program execution - Take care of operator precedence in calculations
- Swapping can be done with or without a temporary variable