0% found this document useful (0 votes)
4 views2 pages

Document (10)

The document contains C code for implementing a simple undirected graph using an adjacency matrix. It includes functions to initialize the graph, add edges, and display the adjacency matrix. The main function demonstrates the usage of these functions by creating a graph and displaying its matrix representation.

Uploaded by

pawargayatri812
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Document (10)

The document contains C code for implementing a simple undirected graph using an adjacency matrix. It includes functions to initialize the graph, add edges, and display the adjacency matrix. The main function demonstrates the usage of these functions by creating a graph and displaying its matrix representation.

Uploaded by

pawargayatri812
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

#include <stdlib.h>

#define MAX_VERTICES 5

Int adjacencyMatrix[MAX_VERTICES][MAX_VERTICES];

Void initializeGraph()

For (int i = 0; i < MAX_VERTICES; i++)

For (int j = 0; j < MAX_VERTICES; j++) {

adjacencyMatrix[i][j] = 0;

Void addEdge(int start, int end)

adjacencyMatrix[start][end] = 1;

adjacencyMatrix[end][start] = 1;

Void displayMatrix() {

For (int i = 0; i < MAX_VERTICES; i++) {

For (int j = 0; j < MAX_VERTICES; j++) {

Printf(“%d “, adjacencyMatrix[i][j]);

Printf(“\n”);

}
Int main() {

initializeGraph();

addEdge(0, 1);

addEdge(0, 3);

addEdge(1, 3);

addEdge(2, 4);

displayMatrix();

return 0;

You might also like