Skip to content

Search

Find a program, subject or material type

CSC206 · Data Structures and Algorithms · Lab Work

Lab 2: Basic input and output

Program with output · 7 pages · Updated Sep 9, 2026

Download

Objective

To understand and practise basic input and output as part of Data Structures and Algorithms.

Theory

Basic input and output is a common task in Data Structures and Algorithms. The program below shows the idea step by step with simple input and clear output.

Program

#include <stdio.h>

int main() {
    int n, i, sum = 0;
    printf("Enter a number: ");
    scanf("%d", &n);

    for (i = 1; i <= n; i++) {
        sum += i;
    }

    printf("Sum of 1 to %d = %d\n", n, sum);
    return 0;
}

Output

Enter a number: 5
Sum of 1 to 5 = 15

Conclusion

In this lab we learned basic input and output and tested it with sample input.