Adjacency Matrix Representation Maker
C Program: Adjacency Matrix Representation Maker
Here is an example of a C program that creates an adjacency matrix representation for a graph:
#include <stdio.h>
#define MAX_SIZE 100
int main() {
int adjMatrix[MAX_SIZE][MAX_SIZE];
int numVertices, i, j;
printf("Enter the number of vertices: ");
scanf("%d", &numVertices);
printf("Enter the adjacency matrix:\n");
for (i = 0; i < numVertices; i++) {
for (j = 0; j < numVertices; j++) {
scanf("%d", &adjMatrix[i][j]);
}
}
printf("Adjacency Matrix Representation:\n");
for (i = 0; i < numVertices; i++) {
for (j = 0; j < numVertices; j++) {
printf("%d ", adjMatrix[i][j]);
}
printf("\n");
}
return 0;
}
This program prompts the user to enter the number of vertices in the graph and then takes input for the adjacency matrix. The adjacency matrix is a square matrix where each cell represents an edge between two vertices. If there is an edge between vertices i and j, the value in the cell (i, j) is 1; otherwise, it is 0.
The program then prints the adjacency matrix representation of the graph.
Please note that this is a basic example, and you may need to modify it based on your specific requirements.
I hope this helps! Let me know if you have any further questions.