Activity: Programming in C Lab

Multi-session hands-on C programming practice with interactive tools

Grade XI • Computer Science ⏱️ Multi-Session

Brief Intro — Programming in C Lab

Reading about code is helpful, but the only way to truly master programming is by rolling up your sleeves and writing it yourself. This multi-session lab provides a structured path for you to practice everything from basic input/output to complex logic and data storage.

In this activity, you'll build your skills through hands-on tasks that cover C fundamentals, control structures, and array manipulation, giving you the practical experience needed to create your own applications.

Prerequisites
Objectives
Session 1: Fundamentals, I/O & Variables

Every C program follows a standard structure, using data types and basic input/output functions to communicate with the user.

C Program Structure

A C program has a standard layout including preprocessor directives, the main() function, and variable declarations.

#include <stdio.h>

int main(void) {
    printf("Hello, World\n");
    return 0;
}
Data Types & Format Specifiers
Data Type Description Format Specifier Size (Typical)
int Integer (whole numbers) %d or %i 4 bytes
float Single-precision floating point %f 4 bytes
double Double-precision floating point %lf 8 bytes
char Single character %c 1 byte
Task 1.1: Basic I/O

Write a program to display an integer, a float, and a double value stored in different variables. Then, modify it to take these values from the user using scanf().

Hint

Declare int a; float b; double c;. Use scanf("%d %f %lf", &a, &b, &c); and then print them back.

Task 1.2: Character & ASCII

Take a character from the user and print both the character and its corresponding ASCII value.

Hint

Use %c to read/print the character and %d to print its integer (ASCII) value.

Task 1.3: Variable Sizes (sizeof)

Write a program to check the size of different variables (short, long, long long, long double) using the sizeof() operator.

Hint

Use printf("Size: %d", sizeof(variable_name));

Task 1.4: Formula-Based Calculations

Implement the following calculations based on user input:

Session 2: Operators & Logic

Operators are the tools for mathematical, relational, and logical manipulation of data.

Interactive Simulator: C Expression Evaluator

Select an operator and enter values to see how C evaluates the expression.

Click Evaluate to see the result
Task 2.1: Arithmetic & Modulus

Take two integers from the user and perform all arithmetic operations (+, -, *, /, %).

Task 2.2: Increment/Decrement

Demonstrate the use of ++ and -- operators in both prefix and postfix forms.

Task 2.3: Swapping Logic

Write two programs to swap two numbers:

  1. Using a third (temporary) variable.
  2. Without using a third variable (Arithmetic method).
Hint (No third variable)

a = a + b; b = a - b; a = a - b;

Task 2.4: Selection Logic

Practice logical decision making:

Session 3: Control Structures (Selection & Iteration)

Control structures give your program the intelligence to make choices and the power to repeat tasks efficiently.

Task 3.1: Switch Case

Write two programs using switch case:

  1. Input a number (1-7) and display the corresponding Day of the Week.
  2. Check whether an entered alphabet is a vowel or a consonant.
Task 3.2: Even/Odd Logic

Write a program to find if an entered integer is odd or even using if-else.

Task 3.3: Loop Ranges & Sums

Practice different loop ranges and accumulations:

Task 3.4: Multiplications & Power

Use a for loop to:

  1. Print the multiplication table of an entered number.
  2. Find the power of a number (e.g., a^b) without using pow().
Task 3.5: Pattern Printing

Write programs to print the following shapes using nested loops:

Session 4: Advanced Number Logic (Important Concepts)

Master these classic algorithms to sharpen your logical thinking and mathematical programming skills.

Task 4.1: Mathematical Properties

Implement logic to process the digits of a number:

Task 4.2: Classical Algorithms

Solve these cornerstone programming problems:

Session 5: Arrays (1D & 2D)

Arrays allow you to store and manage collections of data efficiently using indexed memory locations.

Task 5.1: 1D Array Operations

Practice common array tasks:

Task 5.2: 2D Array Operations

Work with matrices:

  1. Declare a 3x3 matrix, input elements, and print it in grid format.
  2. Write a program to perform addition of two matrices of the same size.
Session 6: Strings & Library Functions

Strings are character arrays with special handling in C, supported by a rich set of library functions.

Task 6.1: String Library Functions

Use string.h functions to:

Task 6.2: Manual String Handling

Re-implement library logic without using string.h:

  1. Find string length using a while loop.
  2. Copy one string to another manually.
Hint

Iterate until you encounter the null character '\0'.

Task 6.3: Math Library Demo

Write a program that uses math.h to demonstrate sqrt(), pow(), and abs().

Ready to test your knowledge?

Take the Assessment →