Search
 
SCRIPT & CODE EXAMPLE
 

C

Adjacency Matrix Representation Maker

/*
 * Program  : Adjacency Matrix Representation of Graph
 * Language : C
 */
#include<stdio.h>
#define V 5

//init matrix to 0
void init(int arr[][V])
{
    int i,j;
    for(i = 0; i < V; i++)
        for(j = 0; j < V; j++)
            arr[i][j] = 0;
}

//Add edge. set arr[src][dest] = 1
void addEdge(int arr[][V],int src, int dest)
{
     arr[src][dest] = 1;
}

void printAdjMatrix(int arr[][V])
{
     int i, j;

     for(i = 0; i < V; i++)
     {
         for(j = 0; j < V; j++)
         {
             printf("%d ", arr[i][j]);
         }
         printf("
");
     }
}

//print the adjMatrix
int main()
{
    int adjMatrix[V][V];

    init(adjMatrix);
    addEdge(adjMatrix,0,1);
    addEdge(adjMatrix,0,2);
    addEdge(adjMatrix,0,3);
    addEdge(adjMatrix,1,3);
    addEdge(adjMatrix,1,4);
    addEdge(adjMatrix,2,3);
    addEdge(adjMatrix,3,4);

    printAdjMatrix(adjMatrix);

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: c bits 
C :: how to read 2d array from a file in c 
C :: highest common factor algorithm in c 
C :: Palindrome number in c program 
C :: how compress string in c 
C :: rust cross compile 
C :: print float number completely in C language 
C :: c median of array 
C :: transfer function exponent matlab 
C :: faire une facture en langage c 
C :: how to merge 2 bytes into an integer 
C :: Turn on the first n Bits in number 
C :: sleep in c 
C :: how to arrange a 2d array based on string length in c 
C :: rust set toolchain 
C :: how to open form in vb.net 
C :: c check if character is lower case 
C :: objects in oops 
C :: C How to define a union? 
C :: address operator 
C :: cast from float to long c 
C :: dev c online 
C :: install lib juicyPixel in haskell 
C :: C static libraries (creating object files) 
C :: C if...else Statement 
C :: condition ternaire in c 
C :: diiferent between * and & in c 
C :: arcpy buffer 
C :: taking input and converting it to a string in c 
C :: openinh VCL file for Vivado HLS 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =