Graph Coloring in C: Unable to identify the logical error
<p>I am trying to implement the graph coloring algorithm in C, this implementation is based on how we assign the colors by iterating through the adjacency matrix. I am unable to get it after assigning a color to the second vertex.</p>

<p>Here is the code of my program:</p>

<pre><code>int n, a[10][10], i, j, k, c[10], max = 0, col, ct = 0, rt = 0, m, count = 2;
void main() {
    printf("enter n\n");
    scanf("%d", &amp;n);
    printf("enter the Adjacency Matrix for %d rows and %d columns\n", n, n);
    for (i = 0; i &lt; n; i++) {
       c[i] = 0;
       for (j = 0; j &lt; n; j++)
           scanf("%d", &amp;a[i][j]);
    }
    c[0] = 1;
    c[1] = 2;
    for (i = 1; i &lt; n; i++) {  
        for (j = 0; j &lt; n; j++)
            if (a[i][j] &gt; 0) {  
                m = 0;
                for (col = 0; col &lt; n; col++) {
                    if (a[i][col] &gt; 0)
                        rt++;
                    if (a[col][i] &gt; 0)
                        ct++;
                }
                m = rt;
                if (ct &gt; rt)
                    m = ct;
                if (m &lt; 2) {
                    if (a[0][i] &gt; 0)
                        c[i] = 2;
                    else
                        c[i] = 1;
                } else {
                    c[i] = count;
                    if (m &gt; max) {
                        max = m;
                        count++;
                    }
                }    
                rt = 0;
                ct = 0;
            }
        if (c[i] &lt; 1)
            if (c[i - 1] &gt; 1)
                c[i] = 1;
            else
                c[i] = 2;
    }
    printf("The proper coloring is\n");
    for (i = 0; i &lt; n; i++)
        printf("c%d=%d ", i + 1, c[i]);
    printf("\n");
}
</code></pre>

<p>Example Input:
Consider a complete graph:</p>

<pre><code>0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
</code></pre>

<p>Expected output:</p>

<pre><code>c1=1 c2=2 c3=3 c4=4
</code></pre>

<p>Observed output:</p>

<pre><code>c1=1 c2=2 c3=3 c4=3
</code></pre>