#include <stdio.h>
#define MAX_NODES 10
// Function to generate the cost of edges in a weighted graph
void generateCost(int graph[MAX_NODES][MAX_NODES], int numNodes) {
printf("Enter the cost of edges in the graph:\n");
for (int i = 0; i < numNodes; i++) {
for (int j = 0; j < numNodes; j++) {
printf("Cost from node %d to node %d: ", i, j);
scanf("%d", &graph[i][j]);
}
}
}
// Function to print the cost of edges in a weighted graph
void printCost(int graph[MAX_NODES][MAX_NODES], int numNodes)
{
printf("\nThe cost of edges in the graph is:\n");
for (int i = 0; i < numNodes; i++) {
for (int j = 0; j < numNodes; j++) {
printf("%d\t", graph[i][j]);
}
printf("\n");
}
}
int main() {
int numNodes;
int graph[MAX_NODES][MAX_NODES];
printf("Enter the number of nodes in the graph: ");
scanf("%d", &numNodes);
// Generate the cost of edges in the graph
generateCost(graph, numNodes);
// Print the cost of edges in the graph
printCost(graph, numNodes);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: