Code:

#include<stdio.h>
#include<conio.h>
#define ROW 5
#define COL 5
int count_connected_set(int A[][COL], int i, int j,int m,int n,int area,int count);
int countIslands(int A[][COL], int m, int n);
int area=0;
int i=1;
int j=1;
int count=0;
int count_connected_set(int A[][COL],int i,int j,int m,int n,int area,int count)
{
A[i][j] = -1;
{
if(A[i-1][j-1]==1 && i>0 && j>0 && i<=m && j<=n ) //NW
count_connected_set(A,i-1,j-1,m,n,area,count);
area += count_connected_set(A, i-1, j-1, m, n);
if(A[i-1][j]==1 && i>0 && j>0 && i<=m && j<=n) //N
count_connected_set(A,i-1,j,m,n,area,count);
area += count_connected_set(A, i-1, j, m, n);
if(A[i-1][j+1]==1 && i>0 && j>0 && i<=m && j<=n)// //NE
count_connected_set(A,i-1,j+1,m,n,area,count);
area += count_connected_set(A, i-1, j+1, m, n);
if(A[i][j-1]==1 && i>0 && j>0 && i<=m && j<=n) //W
count_connected_set(A,i,j-1,m,n,area,count);
area += count_connected_set(A, i, j-1, m, n);
if(A[i][j+1]==1 && i>0 && j>0 && i<=m && j<=n) //E
count_connected_set(A,i,j+1,m,n,area,count);
area += count_connected_set(A, i, j+1, m, n);
if(A[i+1][j-1]==1 && i>0 && j>0 && i<=m && j<=n) //SW
count_connected_set(A,i+1,j-1,m,n,area,count);
area += count_connected_set(A, i+1, j-1, m, n);
if(A[i+1][j]==1 && i>0 && j>0 && i<=m && j<=n) //S
count_connected_set(A,i+1,j,m,n,area,count);
area += count_connected_set(A, i+1, j, m, n);
if(A[i+1][j+1]==1 && i>0 && j>0 && i<=m && j<=n) //SE
count_connected_set(A,i+1,j+1,m,n,area,count);
area += count_connected_set(A, i+1, j+1, m, n);
}
return area;
}
// end of count_connected_set()
int countIslands(int A[][COL], int m, int n)
{
int count = 0;
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
if(A[i][j] == -1)
A[i][j] = 1;
count_connected_set(A, i, j, m, n,area);
count++;
}
}
return count;
}
main()
{
int i,j;
int m = ROW;
int n = COL;
int A[][COL]= { {1, 1, 0, 0, 0},
{0, 1, 0, 0, 1},
{1, 0, 0, 1, 1},
{0, 0, 0, 0, 0},
{1, 0, 1, 0, 1}
};
printf(" %d islands area is %d\n", count_connected_set(count),count_connected_set (area));
printf("Number of islands is: %d\n",countIslands(count));
getch();
}