C Program to Make a Counter Using C Graphics

Write a program in C to make a digital counter using graphics.h header file

In this program, we will make a digital counter that counts from 1 to N in interval of 1 seconds(1000 milliseconds). We will use below mentioned graphics functions in this program.

C program to make a digital counter using graphics

#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <string.h>
#include <dos.h>

int main() {
    int gd = DETECT, gm;
    int i, midx, midy, count;
    char string[100];
    printf("Enter a Number\n");
    scanf("%d", &count);
    initgraph(&gd, &gm, "X:\\TC\\BGI");

    /* get mid positions in x and y-axis */
    midx = getmaxx()/2;
    midy = getmaxy()/2;

 for (i = 0; i <= count; i++) {
     /* draws the gray board */
     setfillstyle(SOLID_FILL, WHITE);
     rectangle(midx - 50, midy - 50, midx + 50, midy + 50);
     floodfill(midx, midy, WHITE);

     /* place the counter inside rectangle */
     sprintf(string, "%s", "Counter");
     settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 5);
     settextjustify(CENTER_TEXT, CENTER_TEXT);
     outtextxy(midx, midy - 100, "Counter");

     /* print the counter value */
     sprintf(string, "%d", i);
     outtextxy(midx, midy, string);

        /* delay for a second(1000 milli second) */

        /* clears screen */

    return 0;
Program Output
Enter a Number
Here is the screen shot of a digital counter. C graphics program to draw a digital counter
Related Topics
C program to make a digital clock
C graphics program to draw concentric circles
C program for bouncing ball animation
C Program to draw a rectangle and bar
C Program to draw sine wave graph on screen
C Program to draw stars in night sky
C graphics program for moving car animation
List of all C Graphics Programs