Thursday 24 April 2014

Write a C program to convert adjacency matrix to Incidence matrix

This program is to convert adjacency matrix to incidence matrix in c program. 


 #include"stdio.h"  
 #include"conio.h"  
 int main()  
 {  
   int a[10][10],b[10][10],i,j,deg=0,n,p,k,l,col=0,row;  
   printf("enter the number of vertices and edges in the graph\n");  
    scanf("%d%d",&n,&p);  
   printf("enter the adjacency matrix elements : \n");  
   for(i=0;i<n;i++)  
   {  
           for(j=0;j<p;j++)  
           {  
                   scanf("%d",&a[i][j]);  
           }  
   }  
 for(k=0;k<n;k++)  
 {  
         for(l=0;l<n;l++)  
         {  
                 b[k][l]=0;  
         }  
 }  
 k=0;  
 l=0;  
 for(i=0;i<p;i++)  
 {col=0;  
         for(j=0;j<n;j++)  
         {  
                 if(a[j][i]==1)  
                 {  
                  k=j;  
                  col++;  
                     if(col==2)  
                     {  
                              b[k][row]=1;  
                              b[row][k]=1;  
                     }                  
                  row=k;  
                  }  
         }  
         if(col==1)  
         {  
              b[k][k]=1;  
         }       
 }   
 printf("the adjacency matrix is : \n\n");  
   for(k=0;k<n;k++)  
 {  
         for(l=0;l<n;l++)  
         {  
                 printf("%d\t",b[k][l]);  
         }  
         printf("\n");  
 }                
 getch();  
 }  

1 comment:
Write comments
  1. What's up, all is going well here and ofcourse every one is sharing data, that's truly fine, keep up writing.


    My web blog; Christian Louboutin Online

    ReplyDelete

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2022