How to display graphics in C language.

In C language, you can use loops and specific output functions to display graphics. Here are some common examples of graphic output.

  1. Output a right triangle:
#include <stdio.h>

int main() {
    int i, j, rows;

    printf("Enter number of rows: ");
    scanf("%d", &rows);

    for (i = 1; i <= rows; ++i) {
        for (j = 1; j <= i; ++j) {
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}
  1. Print an isosceles triangle.
#include <stdio.h>

int main() {
    int i, j, rows, space;

    printf("Enter number of rows: ");
    scanf("%d", &rows);

    space = rows - 1;

    for (i = 1; i <= rows; ++i) {
        for (j = 1; j <= space; ++j) {
            printf(" ");
        }
        space--;

        for (j = 1; j <= 2 * i - 1; ++j) {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}
  1. Output a rectangle.
#include <stdio.h>

int main() {
    int i, j, rows, columns;

    printf("Enter number of rows: ");
    scanf("%d", &rows);
    printf("Enter number of columns: ");
    scanf("%d", &columns);

    for (i = 1; i <= rows; ++i) {
        for (j = 1; j <= columns; ++j) {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}

These are just some simple examples of graphic outputs that you can modify and expand according to your needs.

bannerAds