#include<stdio.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#define max 9001
int ad_mat[max][max];
int main()
{
int i, j, n,deg=0,edge=0,sum=0;
double total_time;
clock_t start,end;
printf("Number of Vertices : ");
scanf("%d",&n);
srand(time(0));
start=clock();
for(i=0;i<n;i++){
for(j=0;j<n;j++){
ad_mat[i][j]=rand()%2;
if(ad_mat[i][j]==1&&i!=j){
ad_mat[j][i]=1;
}
else if(ad_mat[i][j]==0&&i!=j){
ad_mat[j][i]=0;
}
else if(i==j){
ad_mat[i][j]=0;
}
}
}
for(i=0; i<n; i++){
for(j=0; j<n; j++){
printf(" %d",ad_mat[i][j]);
}
printf("\n");
}
printf("\n Vertices \t Degree ");
for ( i = 0 ; i < n ; i++ ){
deg = 0;
for ( j = 0 ; j < n ; j++ )
if ( ad_mat[i][j] == 1)
deg++;
printf("\n\n %5d \t\t %d\n\n", i, deg);
}
for(i=0;i<n;i++){
deg=0;
for(j=0;j<n;j++){
if(ad_mat[i][j]==1){
deg++;
}
if(ad_mat[i][j]==1&&i>=j){
edge++;
}
}
sum+=deg;
}
printf("\n\n The Number of Total Degrees is: %d\n",sum);
printf("\n\n The Number of Total Edges is: %d\n",edge);
printf("\n\n The Number of Edges is=(Summation of Degree/2)=(%d/2)=%d" ,sum,sum/2);
printf("\n\n Therefore Handshaking Theorem is Proved\n\n");
end=clock();
total_time=((double)(end-start)/CLOCKS_PER_SEC)*pow(10,9);
printf("\n Execution time : %1f ns \n",total_time);
printf("\n");
return 0;
}