Skip to content

Search

Find a program, subject or material type

CACS305 · Computer Graphics and Animation · Lab Work

Lab 2: Working with loops

Program with output · 7 pages · Updated Aug 17, 2026

Download

Objective

To understand and practise working with loops as part of Computer Graphics and Animation.

Theory

Working with loops is a common task in Computer Graphics and Animation. 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 working with loops and tested it with sample input.