c program for prims algorithm

#include<stdio.h>
#include<conio.h>
int a,b,u,v,n,i,j,ne=1;
int visited[10]= {	0},min,mincost=0,cost[10][10];
void main() {	
clrscr();	
printf("\n Enter the number of nodes:");	
scanf("%d",&n);	
printf("\n Enter the adjacency matrix:\n");	
for (i=1;i<=n;i++)	  
    for (j=1;j<=n;j++) {		
      scanf("%d",&cost[i][j]);		
      if(cost[i][j]==0)		    
      cost[i][j]=999;	
      }	
    visited[1]=1;	
    printf("\n");	
    while(ne<n) {		
      for (i=1,min=999;i<=n;i++)		  
        for (j=1;j<=n;j++)		    
          if(cost[i][j]<min)		     
          if(visited[i]!=0) {			
          min=cost[i][j];			
          a=u=i;			
          b=v=j;		
          }		
          if(visited[u]==0 || visited[v]==0) 
          {			
            printf("\n Edge %d:(%d %d) cost:%d",ne++,a,b,min);
            mincost+=min;			
            visited[b]=1;		
            }		
          cost[a][b]=cost[b][a]=999;	
          }	
          printf("\n Minimun cost=%d",mincost);
          getch();
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
prims algorithm program in c Prims Algorithm using C prim's algorithm c c program code for prims algorithm prims algorithm in c code prim's algorithm c implementation prims algorithm in c program prims algo in c implement prims algorithm in c prim algorithm in C tracing of prims algorithm prims algorithm graph in python prims mst algorithm with example in c++ java prim kruskal's algorithm and prim's algorithm create explain the greedy strategy involved in Prim&rsquo;s algorithm to find Minimum Spanning Tree prim algorithm for binary trees Write the Prim algorithm prim python is prim's algorithm greedy prims minimum spanning tree prin's algorithm prim algorithm python prims algorithm c Prims &amp; Dijkstra project c++ example Prim algorithm on graphs is for finding minimum spanning tree prim java prims example prim algorithm c++ for powergrid prims cpp prims algorithm code in cpp python prim algorithm prim's algo mst code in c primm's algorithm prim's algorithm inc prim in c c program to implement prim's algorithm to find mst Give algorithm for Prims and Kruskal algorithm. prims algorithm c program Write a program in C to Find Minimum Cost Spanning Tree of an undirected graph using Prim&rsquo;s algorithm. how to program a algorithm in c prince algorithm in c WAP to construct a minimum cost spanning tree of a graph using Prim&rsquo;s algorithm. algorithm for prims and kruskal prims and kruskal algorithm what is the agenda of Prim's and kruskal algorithm prims algorithm code in c c program for prim's algorithm minimum cost spanning tree using prim's Program in c spanning tre eprogtam in c prim implementation c Write a program to implement Prim&rsquo;s algorithm prim algorithm prim's algorithm using adjacency matrix implementation of prim's algorithm in c programming prims algorithm examples matrix prim's algorithm in c++ using adjacency matrix prims algorithm mst c code minimum spanning tree using prim's algorithm c program prims code in c implementation of prims algorithm in c prim's algorithm in c Prim's algorithm i how does prims algorithm work prim algo in c Write a C program to find the minimum spanning tree of the following graph using Prim&rsquo;s algorithm.. code for prims algorithm prims algorithm in c c program to implement prim's algorithm c to implement prim's algorithm prim's algorithm Write a program to find Minimum Cost Spanning Tree of a given undirected graph using Prim's algorithm. prim graph algorithm prim's algorithm on adjacency matrix concept of prism algo primes and kruskal algorithm prims algorithm prims algo code c program for prims algorithm
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source