Posts

Showing posts from September 23, 2018

C Program for Compound Preposition | Discrete Mathematics | C Programming

Compound Preposition One that can be broken down into more primitive propositions. E.g., If it is sunny outside then I walk to work; otherwise I drive, and if it is raining then I carry my umbrella.

C Program To Implement Dijkstra's Algorithm For Finding Shortest Path | C Programming

C Program To Implement Dijkstra's Algorithm For Finding Shortest Path | C Programming #include "stdio.h" #include "conio.h" #define infinity 999 void dij ( int n , int v , int cost [ 10 ][ 10 ], int dist []) {     int i , u , count , w , flag [ 10 ], min ;     for ( i = 1 ; i <= n ; i ++)         flag [ i ] = 0 , dist [ i ] = cost [ v ][ i ];     count = 2 ;     while ( count <= n )     {         min = 99 ;         for ( w = 1 ; w <= n ; w ++)             if ( dist [ w ] < min && ! flag [ w ])                 min = dist [ w ], u = w ;         flag [ u ] = 1 ;         count ++;         for ( w = 1 ; w <= n ; w ++)             if (( dist [ u ] + cost [ u ][ w ] < dist [ w ]) && ! flag [ w ])                 dist [ w ] = dist [ u ] + cost [ u ][ w ];     } } int main () {     int n , v , i , j , cost [ 10 ][ 10 ], dist [ 10 ];     printf ( "Enter the number of nodes:" );     scanf ( "

C Program To Find Minimum Spanning Tree Using Kruskal's Algorithm | C Programming

C Program To Find Minimum Spanning Tree Using Kruskal's Algorithm  #include <stdio.h> #include <conio.h> #include <stdlib.h> int i , j , k , a , b , u , v , n , ne = 1 ; int min , mincost = 0 , cost [ 9 ][ 9 ], parent [ 9 ]; int find ( int ); int uni ( int , int ); int main () {     printf ( " \n\t Implementation of Kruskal's Algorithm \n " );     printf ( " \n Enter the no. of vertices:" );     scanf ( " %d " , & n );     printf ( " \n Enter the cost 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 ;         }     }     printf ( "The edges of Minimum Cost Spanning Tree are \n " );     while ( ne < n )     {         for ( i = 1 , min = 999 ; i <= n ; i ++)         {