Skip to main content

Posts

Showing posts from February, 2014

Prim’s Algorithm For Minimum Spanning Tree In C Programming

#include #include #define size 20 #define infi 9999 void prim(int L[][size],int node) { int T[size],i,j,k; int min_dist,v1,v2,total=0; for(i=1;i OUTPUT ---------------------------------------------------- PRIM`s MINIMUM SPANNING TREE ALGORITHM ---------------------------------------------------- Enter Number of nodes in the Graph:7 Enter Number of Edges in the Graph:12 --------Enter edges and length---------- Enter edge in form {v1,v2}:1 2 Enter Length from 1 to 2:1 Enter edge in form {v1,v2}:1 4 Enter Length from 1 to 4:4 Enter edge in form {v1,v2}:2 3 Enter Length from 2 to 3:2 Enter edge in form {v1,v2}:2 4 Enter Length from 2 to 4:6 Enter edge in form {v1,v2}:2 5 Enter Length from 2 to 5:4 Enter edge in form {v1,v2}:3 6 Enter Length from 3 to 6:6 Enter edge in form {v1,v2}:3 5 Enter Length from 3 to 5:5 Enter edge in form {v1,v2}:4 5 Enter Length from 4 to 5:3 Enter edge in form {v1,v2}:4 7 Enter Length from 4 to 7:4 Enter edge in form {v1,v2}:...

Matrix Multiplication in C Programming

#include int main() { int m, n, p, q, c, d, k, sum = 0; int first[10][10], second[10][10], multiply[10][10]; printf("Enter the number of rows and columns of first matrix\n"); scanf("%d%d", &m, &n); printf("Enter the elements of first matrix\n"); for (c=0;c OUTPUT Enter the number of rows and columns of first matrix 3 3 Enter the elements of first matrix 1 2 3 4 5 6 7 8 9 Enter the number of rows and columns of second matrix 3 3 Enter the elements of second matrix 9 8 7 6 5 4 3 2 1 Product of entered matrices:- 30 24 18 84 69 54 138 114 90

Bubble Sort in C Programming

#include< stdio.h> #include<conio.h> void display(int*,int); void bubble_sort(int*,int); void main() { int i,*a,n; clrscr(); printf("\n Enter number of element you want:"); scanf("%d",&n); for(i=0;i < n;i++) { printf("\n Enter element[%d]:",i); scanf("%d",&a[i]); } printf("\n------------------------------------------"); printf("\n Elements before sorting:"); display(a,n); printf("\n------------------------------------------"); bubble_sort(a,n); printf("\n------------------------------------------"); printf("\n Elements after sorting:"); display(a,n); printf("\n------------------------------------------"); getch(); } void bubble_sort(int *a,int n) { int pass,i,temp; for(pass=0;pass<= n-1;pass++) { for(i=0;i< n-pass-1;i++) { if(a[i]>=a[i+1]) { temp=a[i]; a[i]=a[i+1]; a[i+1]=temp; } } printf("\...