How to normalize a matrix in C?
<p>How to normalize a matrix?</p>

<p>Suppose I have a 2x3 matrix:<br>
1 2 3<br>
4 5 6
The normalized matrix would be:<br>
<code>1/sqrt(pow(2,2) + pow(3,2)) 2/sqrt(pow(2,2) + pow(3,2)) 3/sqrt(pow(2,2) + pow(3,2))<br>
4/sqrt(pow(5,2) + pow(6,2)) 5/sqrt(pow(5,2) + pow(6,2)) 6/sqrt(pow(5,2) + pow(6,2))</code></p>

<p>This is my sample code:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;math.h&gt;

int main(){  
    int rows, cols, rowCounter, colCounter, r, c;  
    int initial[100], inputMatrix[100][100], rowSum[100] = {0}, norm[100][100], square[100] = {0};


    printf("Enter size of a matrix\n");
    scanf("%d %d", &amp;rows, &amp;cols);
    printf("Enter matrix of size %dX%d\n", rows, cols);
    /* Input matrix */
    for(rowCounter = 0; rowCounter &lt; rows; rowCounter++){
        for(colCounter = 0; colCounter &lt; cols; colCounter++){
            scanf("%d", &amp;inputMatrix[rowCounter][colCounter]);
        }
    }



    for(r = 0; r &lt; rows; r++)  
       {  
           for(c = 1; c &lt; cols; c++)  
           {  
               float a;  
               a == inputMatrix[r][c];  
                square[r] += pow(a, 2);  
           }  
           printf("%.2lf ", square[r]);  
       }  

        for(rowCounter = 0; rowCounter &lt; rows; rowCounter++)  
       {  
           for(colCounter = 0; colCounter &lt; cols; colCounter++)  
           {  
               norm[rowCounter][colCounter] == (inputMatrix[rowCounter][colCounter]) / sqrt(square[rowCounter]);  
           }  
       }  
       printf("\nNormalized Matrix:\n");  
       for(rowCounter = 0; rowCounter &lt; rows; rowCounter++)  
       {  
           for(colCounter = 0; colCounter &lt; cols; colCounter++)  
           {  
               printf("%.3lf ", norm[rowCounter][colCounter]);  
           }  
           printf("\n");  
       }  

        getch();  
        return 0;  
    }  
</code></pre>