Thursday, 24 April 2014

C program to check whether the Graph is Euler is not

#include<stdio.h>
#include<conio.h>

void main()
{

  int i,j;
  int flag=0,count;
  int total;
  int R[10],C[10],m,a[10][10];
  clrscr();

  printf("\n @@@ Enter the no of vertices in a graph : @@@\n-> ");
  scanf ("%d",&m);
  printf ("\n Enter the adjacency matrix :  \n");
  for (i=0;i<m;i++)
  {
    for(j=0;j<m;j++)
          {
              printf ("Enter %d row and ",i);
              printf (" %d column -> ",j);
           scanf("%d",&a[i][j]);
          }
  }
  printf ("\n>>> The entered adjacency matrix is \n" );
  for (i=0;i<m;i++)
  {
    for(j=0;j<m;j++)
          {
           printf ("%3d",a[i][j]);
          }
          printf ("\n");
  }
printf ("\n>> Degree each vertices are : ");

  total=0;
  for (i=0;i<m;i++)
  {
    count=0;
    for(j=0;j<m;j++)
          {
             if ( a[i][j]==1 && i!=j)
                {
                       count=count+1;
                }
                       else
                              if(i==j && a[i][j]==1)
                         {
                              count=count+2;
                         }

          }
               total=total+count;
               if (count%2==0)
                   {
                      flag=flag+count;
                   }

  }
  printf ("\n>> Total degree is   = %d",total);

            if (flag==total)
               {
                      printf ("\n>> The graph is eular");
               }
                 else
                 {
                       printf ("\n>> The graph is not eular");
                 }

  getch();

}


No comments:
Write comments

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-2016