Boundary Fill Algorithm in C and C++

Here you will learn about boundary fill algorithm in C and C++.

Boundary Fill is another seed fill algorithm in which edges of the polygon are drawn. Then starting with some seed any point inside the polygon we examine the neighboring pixels to check whether the boundary pixel is reached. If boundary pixels are not reached, pixels are highlighted and process is continued until boundary pixels are reached.

Also Read: Flood Fill Algorithm in C and C++

Flood Fill Algorithm in C and C++

4 Connected Region (Image Source)

Following is the algorithm for filling a region in a recursive manner with color specified fill color (f_color) up to a boundary color specified boundary color (b_color)


1. Create a function named as boundaryfill with 4 parameters (x,y,f_color,b_color).

2. Call it recursively until the boundary pixels are reached.

3. Stop.

Program for Boundary Fill Algorithm in C and C++

C Program

C++ Program

Author Bio:

I am Rahul Maheshwari from India currently pursuing engineering degree in Computer Science. I am passionate about programming and loves to code as much as I can and likes to help people to become better in programming.

Connect with him: Facebook | Linkedin

Comment below if you have doubts or found anything incorrect in above boundary fill algorithm in C and C++.

5 thoughts on “Boundary Fill Algorithm in C and C++

  1. ssd

    when we change the values of f_color and b_color the program doesnt work the how should we change the color

    1. EV

      boundary colour u have to keep fixed as 15, fill colour u can choose any from 0 to 15.

  2. EV

    The program is not working properly for circle with radius more than 45 in Dosbox (Turbo C for windows), in Dev C++ it is working fine for any radius , can somebody tell what changes should be made in turbo c program?

  3. milan

    when we give radius more than 40 it doesn’t fill color…


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.