#include<stdio.h> #include<conio.h> int main() { int i,k,j,l,m,a[10][10],c[10][10],b[10][10],d[10][10],sumd=0,tng; printf(" Enter the no of vertices: "); scanf ("%d",&m); printf ("@@@Enter the adjacency of matrix: @@@\n"); for (i=1;i<=m;i++) { for(j=1;j<=m;j++) { scanf("%d",&a[i][j]); } } for (i=1;i<=m;i++) { for(j=1;j<=m;j++) { b[i][j]=a[i][j]; } } printf("Multiplication of matrix (A*A)\n"); for(i=1;i<=m;i++) { for(j=1;j<=m;j++) { c[i][j]=0; for(k=1;k<=m;k++) { c[i][j]=c[i][j]+(a[i][k]*b[k][j]); } } } for(i=1;i<=m;i++) { for(j=1;j<=m;j++) { d[i][j]=0; for(l=1;l<=m;l++) { d[i][j]=d[i][j]+(a[i][l]*c[l][j]); } } } for(i=1;i<=m;i++) { for(j=1;j<=m;j++) { printf("%3d",c[i][j]); } printf("\n"); } printf("Multiplication of matrix (A*A*A)"); printf("\n"); for(i=1;i<=m;i++) { for(j=1;j<=m;j++) { printf("%3d",d[i][j]); } printf("\n"); } printf("Displaying and sum of the diagonal element"); for(i=1;i<=m;i++) { for(j=1;j<=m;j++) { if(i==j) { printf("\n%d", d[i][j]); sumd=sumd+d[i][j]; } } printf("\n"); } printf("\nSum of the diagonal of a3 matrix: %d\n",sumd); tng=sumd/6; printf("Number of triangles in a given graph: %d",tng); getch(); }
Thursday, 24 April 2014
C program to find the number of triangle in the given Graph
Subscribe to:
Post Comments (Atom)
hello sir, can u just tell me how to display the vertices of found triangle in the graph?
ReplyDeletehello sir, how to display the vertices of found triangle?
ReplyDeletehello sir, how to display the vertices of found triangle?
ReplyDeleteThis is all done with maths calculation but for traceing the found triangle you may suppose to chose different method.
ReplyDelete