answersLogoWhite

0


Best Answer

#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();

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Source code for prim's algorithm in C plus plus programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is writing Code?

Writing code is the process of implementing an algorithm in a specific programming language.


How do i get source code for bide algoritham?

You can get the Java source code for the BIDE data mining algorithm here : (link moved to link section) It is an open-source data mining framework that includes the BIDE algorithm


Computer programming vs algorithm?

An algorithm describes the finite procedural steps required to solve a problem. Algorithms are typically written so humans can easily understand those steps. Computer programming is the means by which a computational problem is converted into executable code. This often entails the development of algorithms which must be converted from the human-readable form into native machine code, typically using high-level programming languages to produce the abstract, human-readable source code, and compilers or interpreters to produce the machine-readable code.


Why do you write your code in a Notepad file?

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.


How to write algorithm in c program?

Algorithms are created using pseudocode, which is a combination of natural language (such as English) and commonly understood programming concepts. Pseudocode is a machine-independent language, but it is far too abstract for a machine to understand. It is intended for humans only. As programmers, our job is to translate these algorithms into a form the machine can process in order to produce the required machine-dependent code. For this we use programming languages, such as C, C++ and Java. The more abstract the programming language, the easier it is to convert an algorithm into working code. Of all the high-level programming languages, C has the least amount of abstraction, however we can make use of third party libraries to increase the amount of abstraction, or we can use the language itself to create our own abstractions.

Related questions

Can someone provide the C program for Prim's algorithm?

The C code for Prim's algorithm can be found in the following link. https://sites.google.com/site/itstudentjunction/lab-programming-solutions/data-structures-programs/program-to-find-minimal-spanning-tree-using--prims-algorithm


What is writing Code?

Writing code is the process of implementing an algorithm in a specific programming language.


Is During the planning stage an algorithm is written in programming code?

True!


Where do you get the exact source code in C that implements lossless compression algorithm?

The source code, in C, will depend on what type of lossless compression algorithm will be used. A source code should be available from various computer scientists in your area.


Getting source code of c?

C is a programming language, so it doesn't have source code.(On the other hand, C compilers do have source code, but you, as a beginner in programming, could not understand them.)


How do i get source code for bide algoritham?

You can get the Java source code for the BIDE data mining algorithm here : (link moved to link section) It is an open-source data mining framework that includes the BIDE algorithm


Computer programming vs algorithm?

An algorithm describes the finite procedural steps required to solve a problem. Algorithms are typically written so humans can easily understand those steps. Computer programming is the means by which a computational problem is converted into executable code. This often entails the development of algorithms which must be converted from the human-readable form into native machine code, typically using high-level programming languages to produce the abstract, human-readable source code, and compilers or interpreters to produce the machine-readable code.


Java source code for median filter algorithm?

research is going on to develop a source code for median filtering using java


What is open-source programming?

It is programming that is licensed in such a way that it provides the source code for everyone to view and suggest changes to, and is usually at no cost or a very lost cost to anyone that wants the program and its source code.


What does src for ShockAhpi do?

In computer programming, src usually means 'source code'. The src contains the source code for ShockAhpi.


Microsoft office's source code written by which programming language?

C++


Why do you write your code in a Notepad file?

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.