The below given program converts incidence matrix elements to adjacency matrix elements.
#include<stdio.h> #include<conio.h> int main() { int a[10][10],b[10][10],i,j,deg=0,n,p,k,l; printf("enter the number of vertices in the graph\n"); scanf("%d",&n); printf("enter the adjacency matrix elements : \n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } // printf("the degree of each vertex is : \n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { if((i!=j) && a[i][j]==1) { deg++; } else if(a[i][j]==1) { deg=deg+2; } } //printf("the degree of V%d = %d\n",i,deg); } p=deg/2; for(k=0;k<n;k++) { for(l=0;l<p;l++) { b[k][l]=0; } } k=0; l=0; for(i=0;i<n;i++) { for(j=i;j<n;j++) { if(a[i][j]==1) { k=i; b[k][l]=1; k=j; b[k][l]=1; l++; } } } printf("the Incidence matrix is : \n\n"); for(k=0;k<n;k++) { for(l=0;l<p;l++) { printf("%d\t",b[k][l]); } printf("\n"); } getch(); }
No comments:
Write comments