C Program for Digital Counter Using C Graphics

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

In this tutorial, we are going to create a C Program for Digital Counter using C Graphics. It will count from 1 to a given number N in intervals of 1 second(i.e., thousand milliseconds). In this article, we will be introducing you to the concepts individually.

C Program for Digital Counter Using C Graphics

1. Concepts

The following concepts will be used in a C Program For Digital Counter Using C Graphics. To Develop This C Program, You Must Understand These Concepts.

  • initgraph
  • setfillstyle
  • detectgraph
  • ellipse
  • floodfill
  • settextjustify
  • rectangle
  • closegraph

2. C Program For Digital Counter Using C Graphics

The C Program For Digital Counter Using C Graphics is following:

#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");
    midx = getmaxx()/2;
    midy = getmaxy()/2;
 for (i = 0; i <= count; i++) {
     setcolor(WHITE);
     setfillstyle(SOLID_FILL, WHITE);
     rectangle(midx - 50, midy - 50, midx + 50, midy + 50);
     floodfill(midx, midy, WHITE);
     setcolor(BLUE);
     sprintf(string, "%s", "Counter");
     settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 5);
     settextjustify(CENTER_TEXT, CENTER_TEXT);
     outtextxy(midx, midy - 100, "Counter");
     sprintf(string, "%d", i);
     outtextxy(midx, midy, string);
        delay(1000);
        cleardevice();
    }
    getch();
    closegraph();
    return 0;
}

3. Output

The output of C Program for Digital Counter Using C Graphics

4. Resources

Here are the files used in this  C Program For Digital Counter Using C Graphics. You can download these files to run on your own device or computer:

Similar Posts

Leave a Reply

Your email address will not be published.