C Programming Theory and Practical Guide
Practical Programs in C
Practical No. 01: Print "Hello World"
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
Practical No. 03: Sum of Two Numbers
#include <stdio.h>
int main() {
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
sum = a + b;
printf("Sum = %d", sum);
return 0;
Practical No. 04: Find Largest of Three Numbers
#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three numbers: ");
C Programming Theory and Practical Guide
scanf("%d%d%d", &a, &b, &c);
if (a >= b && a >= c)
printf("%d is largest", a);
else if (b >= a && b >= c)
printf("%d is largest", b);
else
printf("%d is largest", c);
return 0;
Practical 7A: Table of any number
#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
for (int i = 1; i <= 10; i++)
printf("%d x %d = %d\n", n, i, n*i);
return 0;
Practical 7B: Print Even or Odd numbers from 1 to N
#include <stdio.h>
int main() {
int n;
C Programming Theory and Practical Guide
printf("Enter limit: ");
scanf("%d", &n);
printf("Even numbers:\n");
for (int i = 1; i <= n; i++)
if (i % 2 == 0) printf("%d ", i);
return 0;
Practical 08: Swapping of Two Numbers
#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
temp = a;
a = b;
b = temp;
printf("After swapping: a=%d, b=%d", a, b);
return 0;
Practical 09: Sum and Average of Five Numbers
#include <stdio.h>
int main() {
int i, num, sum = 0;
C Programming Theory and Practical Guide
float avg;
for (i = 1; i <= 5; i++) {
printf("Enter number %d: ", i);
scanf("%d", &num);
sum += num;
avg = sum / 5.0;
printf("Sum = %d, Average = %.2f", sum, avg);
return 0;
Debugging Process
Debugging is the process of identifying and removing errors (bugs) in a program.
Steps:
1. Code Compilation - Identify syntax errors.
2. Execution - Run the program.
3. Error Detection - Analyze incorrect output or crashes.
4. Breakpoints - Stop program at specific lines.
5. Variable Watch - Monitor variable values.
6. Fix and Retest - Correct logic and rerun.
System Development Life Cycle (SDLC)
C Programming Theory and Practical Guide
1. Requirement Analysis - Understand user needs.
2. System Design - Design architecture.
3. Implementation - Coding the software.
4. Testing - Debug and verify.
5. Deployment - Release software.
6. Maintenance - Fix errors, update features.
Language Translator
A language translator converts high-level code into machine code.
Types:
1. Compiler - Converts entire code (e.g., C).
2. Interpreter - Line-by-line execution (e.g., Python).
3. Assembler - Converts assembly to machine code.
IDE of C Language
An IDE (Integrated Development Environment) provides tools to write, compile, debug, and run programs.
Components:
- Editor - Code writing
- Compiler - Code translation
- Debugger - Error fixing
- Output Window - Display results
C Programming Theory and Practical Guide
Examples: Turbo C++, Code::Blocks, Dev C++, Visual Studio
Structured Programming
A programming technique that uses clear structure such as functions, loops, and conditions to improve
readability.
Program Development Life Cycle
1. Problem Definition
2. Design (Algorithm/Flowchart)
3. Coding
4. Testing
5. Documentation
6. Maintenance
If Statement & Flowchart
Syntax:
if (condition) {
// code
Example:
C Programming Theory and Practical Guide
if (a > b)
printf("a is greater");
Flowchart:
[Start]
[Condition?] --Yes--> [Execute Block]
No
[End]
Switch Statement
Syntax:
switch(expression) {
case value1: code; break;
case value2: code; break;
default: default_code;
Example:
int day = 3;
switch(day) {
case 1: printf("Mon"); break;
C Programming Theory and Practical Guide
case 2: printf("Tue"); break;
case 3: printf("Wed"); break;
default: printf("Invalid");
User Defined Function
Steps:
1. Function Declaration:
int add(int, int);
2. Function Definition:
int add(int a, int b) {
return a + b;
3. Function Call:
int result = add(3, 4);