c program for prims algorithm

Solutions on MaxInterview for c program for prims algorithm by the best coders in the world

showing results for - "c program for prims algorithm"
Elias
10 Aug 2020
1#include<stdio.h>
2#include<conio.h>
3int a,b,u,v,n,i,j,ne=1;
4int visited[10]= {	0},min,mincost=0,cost[10][10];
5void main() {	
6clrscr();	
7printf("\n Enter the number of nodes:");	
8scanf("%d",&n);	
9printf("\n Enter the adjacency matrix:\n");	
10for (i=1;i<=n;i++)	  
11    for (j=1;j<=n;j++) {		
12      scanf("%d",&cost[i][j]);		
13      if(cost[i][j]==0)		    
14      cost[i][j]=999;	
15      }	
16    visited[1]=1;	
17    printf("\n");	
18    while(ne<n) {		
19      for (i=1,min=999;i<=n;i++)		  
20        for (j=1;j<=n;j++)		    
21          if(cost[i][j]<min)		     
22          if(visited[i]!=0) {			
23          min=cost[i][j];			
24          a=u=i;			
25          b=v=j;		
26          }		
27          if(visited[u]==0 || visited[v]==0) 
28          {			
29            printf("\n Edge %d:(%d %d) cost:%d",ne++,a,b,min);
30            mincost+=min;			
31            visited[b]=1;		
32            }		
33          cost[a][b]=cost[b][a]=999;	
34          }	
35          printf("\n Minimun cost=%d",mincost);
36          getch();
37}
queries leading to this page
minimum spanning tree using prim 27s algorithm c programprim pythonkruskal 27s algorithm and prim 27s algorithm createprim algorithm c 2b 2b for powergridprims algo codewrite a c program to find the minimum spanning tree of the following graph using prim e2 80 99s algorithm prims algorithm using cwhat is the agenda of prim 27s and kruskal algorithmwrite a program to find minimum cost spanning tree of a given undirected graph using prim 27s algorithm prims algorithmwrite a program in c to find minimum cost spanning tree of an undirected graph using prim e2 80 99s algorithm implementation of prims algorithm in cspanning tre eprogtam in cprims algorithm c programprims algorithm in c languageprim algorithmcode for prims algorithmprim graph algorithmminimum cost spanning tree using prim 27s program in cprim 27s algorithm in cprims algorithm mst c codec program code for prims algorithmprims algorithm code in cppprims algorithm code in cimplement prims algorithm in calgorithm for prims and kruskalprim in cprims algorithm examples matrixc to implement prim 27s algorithmhow to program a algorithm in c prims and kruskal algorithmprim 27s algo mst code in cprin 27s algorithmjava primtracing of prims algorithmprims algorithm c codeprim 27s algorithm c programprim algorithm for binary treesc program for prim 27s algorithmprim implementation cprim algo in cprims algorithm graph in pythonprims code in cexplain the greedy strategy involved in prim e2 80 99s algorithm to find minimum spanning treeprim 27s algorithm iwrite the prim algorithmprims minimum spanning treeimplement prim e2 80 99s algorithm in cprim 27s algorithm c implementationconcept of prism algoprince algorithm in cminimum spanning tree prim javaprims examplepython prim algorithmprims mst algorithm with example in c 2b 2bprim 27s algorithm on adjacency matrixhow does prims algorithm workgive algorithm for prims and kruskal algorithm prims algorithm program in cprims algorithm in c programwap to construct a minimum cost spanning tree of a graph using prim e2 80 99s algorithm prim algorithm pythonprims algorithm cprims algorithm in c codewrite a program to implement prim e2 80 99s algorithmprims cppprim algorithm on graphs is for finding c program to implement prim 27s algorithm to find mstprimm 27s algorithmprim 27s algorithm cprims 26 dijkstra project c 2b 2b exampleprim in c programizprim 27s algorithm using adjacency matrixprims in cprims algo in cprim algorithm in cis prim 27s algorithm greedyprims algorithm in cprim 27s algorithm c codeprim 27s algorithmprim 27s algorithm incimplementation of prim 27s algorithm in c programmingc program to implement prim 27s algorithmprimes and kruskal algorithmprim 27s algorithm code in c languagec program for prims algorithmprim 27s algorithm in c 2b 2b using adjacency matrixc program for prims algorithm