Iterative depth first search using adjacency matrix I have written code for graph traversal using adjacency matrices in an iterative approach. The code should print the graph in a DFS way.

#include &lt;iostream&gt;
using namespace std;
int main(){
    int n;
    cin&gt;&gt;n;
    int c[n][n];
    int i,j;
    for(i=0;i&lt;n;i++){
        for(j=0;j&lt;n;j++){
            cin&gt;&gt;c[i][j];
        }
    }
    int dfs[n];
    for(i=0;i&lt;n;i++){
        dfs[i]=-1;
    }
    dfs[0]=1;
    j=1;
    for(i=0;i&lt;n;i++){
        if(dfs[i]==1&amp;&amp;i&gt;j)
        cout&lt;&lt;i;
        dfs[i]=1;
        while(c[i][j]!=0&amp;&amp;j&lt;n&amp;&amp;i&lt;n){
            if(dfs[j]==-1)
            {
                dfs[j]=1;
            }
            if(dfs[j]==1){
                cout&lt;&lt;j;
                j++;
            }
        }
    }
}


Is my code correct? If not, correct me. Can we decrease time complexity?
It's nearly impossible to tell what your code does because:


The variable names are meaningless
There are no prompts for the user to tell them what the inputs mean
The output appears to just be a string of numbers with no apparent meaning


I can't tell you if it's correct or not (which is beyond the scope of Code Review anyway) because I can't tell what it's trying to do. In terms of trying to improve your code, I recommend changing the variable names from single letters or cryptic acronyms to full words, such as adjacencyMatrix and traversalList, or whatever they actually represent.

I recommend outputting some strings to tell the user what to input. Alternately, if this code is supposed to read its input from a file, then you should write code to read from a file instead of assuming it will come from standard in.

Finally, your output should say what it's outputting and have some sort of separators between the values, such as commas, spaces, or line endings. Again, if it's meant to be outputting to a file, then you should write code to write to a file rather than standard out.